Spaces:
Running
Running
Commit
·
70760e8
1
Parent(s):
295cef6
Update main.py
Browse files
main.py
CHANGED
@@ -115,19 +115,16 @@ def proxy(url):
|
|
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 |
-
|
122 |
-
|
|
|
|
|
|
|
123 |
|
124 |
-
return Response(req.iter_content(chunk_size=1024), content_type=req.headers['content-type'])
|
125 |
-
|
126 |
except Exception as e:
|
127 |
-
#logging.error(f"Error in proxy: {str(e)}")
|
128 |
-
#print('Skipped')
|
129 |
-
#return redirect(url_for('index', new='true'))
|
130 |
-
|
131 |
logging.error(f"Error in proxy: {str(e)}")
|
132 |
return Response("Error", status=500)
|
133 |
|
@@ -188,5 +185,10 @@ def index():
|
|
188 |
id=id,
|
189 |
page_title=page_title)
|
190 |
|
|
|
|
|
|
|
|
|
|
|
191 |
if __name__ == '__main__':
|
192 |
app.run(host='0.0.0.0', port='7860')
|
|
|
115 |
|
116 |
logging.info(f"Sending request to: {clean_url}")
|
117 |
req = requests.get(clean_url, headers=headers, stream=True, timeout=2)
|
118 |
+
def generate():
|
119 |
+
for chunk in req.iter_content(chunk_size=1024):
|
120 |
+
if 'abort' in session and session['abort']:
|
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)
|
130 |
|
|
|
185 |
id=id,
|
186 |
page_title=page_title)
|
187 |
|
188 |
+
@app.route('/abort_stream')
|
189 |
+
def abort_stream():
|
190 |
+
session['abort'] = True
|
191 |
+
return 'Aborted', 200
|
192 |
+
|
193 |
if __name__ == '__main__':
|
194 |
app.run(host='0.0.0.0', port='7860')
|