-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
34 lines (26 loc) · 829 Bytes
/
Copy pathapp.py
File metadata and controls
34 lines (26 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import urllib2
from flask import request
from flask import Flask
from flask import Response
app = Flask(__name__)
@app.route('/')
def root():
"""
Proxies the provided url
"""
url = request.args.get('url', '')
usage = 'Pass a properly encoded url parameter e.g. /?url=http://www.google.com'
if url:
f = urllib2.urlopen(url)
response = f.read()
status = f.getcode()
headers = f.headers.dict
content_type = headers.get('content-type', 'text/html')
return Response(response=response, status=status, headers=headers, content_type=content_type)
else:
return usage
if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)