-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhttpdump.py
executable file
·48 lines (38 loc) · 1.25 KB
/
httpdump.py
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
47
48
#!/usr/bin/env python2.7
#
# IMPORTS
#
from argparse import ArgumentParser
from paste import httpserver
import signal
import webapp2
#
# CLASSES
#
class DumpHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('method: %s\n' % self.request.method)
self.response.write('url: %s\n' % self.request.url)
for k, v in self.request.headers.iteritems():
self.response.write('headers[\'%s\']: %s\n' % (k, v))
if len(self.request.GET) > 0:
for k, v in self.request.GET.iteritems():
self.response.write('GET[\'%s\']: %s\n' % (k, v))
if len(self.request.POST) > 0:
for k, v in self.request.POST.iteritems():
self.response.write('POST[\'%s\']: %s\n' % (k, v))
#
# MAIN
#
def main():
# override annoying python SIGINT handling
signal.signal(signal.SIGINT, signal.SIG_DFL)
parser = ArgumentParser(description='A webserver')
parser.add_argument('-p', '--port', default=8080, type=int, help='Server port')
args = parser.parse_args()
routes = [(r'/.*', DumpHandler)]
webapp = webapp2.WSGIApplication(routes=routes, debug=True)
httpserver.serve(webapp, port=args.port, use_threadpool=True, daemon_threads=True)
if __name__ == '__main__':
main()