Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.cgi
More file actions
Latest commit
executable file
·46 lines (35 loc) · 1.14 KB
/
Copy pathserver.cgi
File metadata and controls
executable file
·46 lines (35 loc) · 1.14 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
41
42
43
44
45
46
#!/usr/bin/python
importrequests
importos
importsys
fromwsgiref.handlersimportCGIHandler
ifsys.version_info< (3,):
defb(x):
returnx
else:
importcodecs
defb(x):
returncodecs.latin_1_encode(x)[0]
defapplication(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'inos.environelse'none',
'getenv-proxy': os.getenv('HTTP_PROXY', 'none'),
'wsgi-env-proxy': environ['HTTP_PROXY'] if'HTTP_PROXY'inenvironelse'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)]
if__name__=='__main__':
CGIHandler().run(application)