Created
August 29, 2019 08:27
-
-
Save straxico/fd5bf4b2fade8921086851f305590a9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Jun 26 11:42:12 2019 | |
@author: mehran | |
""" | |
# -*- coding: utf-8 -*- | |
import flask | |
import requests | |
app = flask.Flask(__name__) | |
method_requests_mapping = { | |
'GET': requests.get, | |
'HEAD': requests.head, | |
'POST': requests.post, | |
'PUT': requests.put, | |
'DELETE': requests.delete, | |
'PATCH': requests.patch, | |
'OPTIONS': requests.options, | |
} | |
@app.route('/<path:url>', methods=method_requests_mapping.keys()) | |
def proxy(url): | |
requests_function = method_requests_mapping[flask.request.method] | |
request = requests_function(url, stream=True, params=flask.request.args) | |
response = flask.Response(flask.stream_with_context(request.iter_content()), | |
content_type=request.headers['content-type'], | |
status=request.status_code) | |
response.headers['Access-Control-Allow-Origin'] = '*' | |
response.headers['Access-Control-Allow-Headers'] = '*' | |
return response | |
if __name__ == '__main__': | |
# Bind to PORT if defined, otherwise default to 5000. | |
app.run(host='0.0.0.0', port=5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment