Starchik1 commited on
Commit
b37cd5f
·
verified ·
1 Parent(s): 2e34772

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +18 -2
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(image_url, timeout=30)
26
- return Response(resp.content, mimetype=resp.headers['Content-Type'])
 
 
 
 
 
 
 
 
 
 
 
 
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