Update main.py
Browse files
main.py
CHANGED
@@ -21,9 +21,25 @@ def proxy_image():
|
|
21 |
return 'No URL provided', 400
|
22 |
|
23 |
try:
|
|
|
|
|
|
|
|
|
24 |
# Forward the request to get the image
|
25 |
-
resp = requests.get(
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
except Exception as e:
|
28 |
logger.error(f"Error proxying image: {str(e)}")
|
29 |
return str(e), 500
|
|
|
21 |
return 'No URL provided', 400
|
22 |
|
23 |
try:
|
24 |
+
# Get headers from the incoming request
|
25 |
+
headers = {key: value for key, value in request.headers if key.lower() != 'host'}
|
26 |
+
headers['Referer'] = TARGET_BASE_URL
|
27 |
+
|
28 |
# Forward the request to get the image
|
29 |
+
resp = requests.get(
|
30 |
+
image_url,
|
31 |
+
headers=headers,
|
32 |
+
cookies=request.cookies,
|
33 |
+
timeout=30,
|
34 |
+
allow_redirects=True
|
35 |
+
)
|
36 |
+
|
37 |
+
# Check response status
|
38 |
+
if resp.status_code != 200:
|
39 |
+
logger.error(f"Error response from target: {resp.status_code}")
|
40 |
+
return f"Error: {resp.status_code}", resp.status_code
|
41 |
+
|
42 |
+
return Response(resp.content, mimetype=resp.headers.get('Content-Type', 'image/jpeg'))
|
43 |
except Exception as e:
|
44 |
logger.error(f"Error proxying image: {str(e)}")
|
45 |
return str(e), 500
|