Skip to content

Instantly share code, notes, and snippets.

@mapix
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save mapix/733ce5e3352432e31e96 to your computer and use it in GitHub Desktop.

Select an option

Save mapix/733ce5e3352432e31e96 to your computer and use it in GitHub Desktop.
# -*- 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