-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.wsgi
More file actions
40 lines (31 loc) · 1.02 KB
/
server.wsgi
File metadata and controls
40 lines (31 loc) · 1.02 KB
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
35
36
37
38
39
40
import requests
import sys
import os
if sys.version_info < (3,):
def b(x):
return x
else:
import codecs
def b(x):
return codecs.latin_1_encode(x)[0]
def application(environ, start_response):
status = '200 OK'
r = requests.get("http://example.com/")
output = """
Made internal subrequest to http://example.com/ and got:
os.environ[HTTP_PROXY]: %(proxy)s
os.getenv('HTTP_PROXY'): %(getenv-proxy)s
wsgi Proxy header: %(wsgi-env-proxy)s
status code: %(status)d
text: %(text)s
""" % {
'proxy': os.environ['HTTP_PROXY'] if 'HTTP_PROXY' in os.environ else 'none',
'getenv-proxy': os.getenv('HTTP_PROXY', 'none'),
'wsgi-env-proxy': environ['HTTP_PROXY'] if 'HTTP_PROXY' in environ else 'none',
'status': r.status_code,
'text': r.text
}
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(b(output))))]
start_response(status, response_headers)
return [b(output)]