Last active
August 29, 2015 14:05
-
-
Save mapix/733ce5e3352432e31e96 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -*- | |
| import requests | |
| from urlparse import urlparse | |
| from flask import Flask | |
| from flask import Response | |
| from flask import request | |
| from flask import stream_with_context | |
| app = Flask(__name__) | |
| @app.route('/', defaults={'path': ''}, methods=['GET', 'POST', 'DELETE']) | |
| @app.route('/<path:path>', methods=['GET', 'POST', 'DELETE']) | |
| def home(path): | |
| target_url = urlparse(request.url)._replace(query='').geturl() | |
| params = {k: v for k, v in request.args.items()} | |
| forms = {k: v for k, v in request.form.items()} | |
| resp = requests.request(request.method, target_url, params=params, data=forms, stream=True) | |
| return Response(stream_with_context(resp.iter_content()), content_type=resp.headers['content-type']) | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment