Commit
·
31c4438
1
Parent(s):
82bee64
Update main.py
Browse files
main.py
CHANGED
|
@@ -109,21 +109,22 @@ def proxy(url):
|
|
| 109 |
|
| 110 |
clean_url = full_url.replace('proxy/', '')
|
| 111 |
clean_url = encode_url(clean_url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
try:
|
| 114 |
start = time.time()
|
| 115 |
-
|
| 116 |
logging.info(f"Sending request to: {clean_url}")
|
| 117 |
req = requests.get(clean_url, headers=headers, stream=True, timeout=2)
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
session['abort'] = False
|
| 122 |
-
break
|
| 123 |
-
yield chunk
|
| 124 |
-
|
| 125 |
-
return Response(generate(), content_type=req.headers['content-type'])
|
| 126 |
-
|
| 127 |
except Exception as e:
|
| 128 |
logging.error(f"Error in proxy: {str(e)}")
|
| 129 |
return Response("Error", status=500)
|
|
|
|
| 109 |
|
| 110 |
clean_url = full_url.replace('proxy/', '')
|
| 111 |
clean_url = encode_url(clean_url)
|
| 112 |
+
should_abort = lambda: 'abort' in session and session['abort']
|
| 113 |
+
|
| 114 |
+
def generate(should_abort):
|
| 115 |
+
for chunk in req.iter_content(chunk_size=1024):
|
| 116 |
+
if should_abort():
|
| 117 |
+
break
|
| 118 |
+
yield chunk
|
| 119 |
|
| 120 |
try:
|
| 121 |
start = time.time()
|
| 122 |
+
|
| 123 |
logging.info(f"Sending request to: {clean_url}")
|
| 124 |
req = requests.get(clean_url, headers=headers, stream=True, timeout=2)
|
| 125 |
+
|
| 126 |
+
return Response(generate(should_abort), content_type=req.headers['content-type'])
|
| 127 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
except Exception as e:
|
| 129 |
logging.error(f"Error in proxy: {str(e)}")
|
| 130 |
return Response("Error", status=500)
|