Last active
December 14, 2015 01:49
-
-
Save carl-olin/5008872 to your computer and use it in GitHub Desktop.
Minimal webproxy
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
#! /usr/bin/env python | |
from flask import Flask, Response, url_for, request | |
import requests | |
PROXY_URL = "http://www.aftonbladet.se" | |
app = Flask(__name__) | |
@app.route('/<path:path>') | |
def sub_url(path): | |
url = "%s/%s?&%s" % (PROXY_URL, path, request.query_string) | |
return get_reponse(url) | |
@app.route('/') | |
def base_url(): | |
url = "%s?&%s" % (PROXY_URL, request.query_string) | |
return get_reponse(url) | |
def get_reponse(url): | |
resp = requests.get(url) | |
headers = resp.headers | |
return Response(resp.content, status=resp.status_code, | |
mimetype=headers["content-type"]) | |
if __name__ == '__main__': | |
app.run(debug=True, host='0.0.0.0', ssl_context='adhoc') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment