1
|
1 #!/usr/bin/env python
|
|
2
|
|
3 """
|
|
4 dump HTTP requests
|
|
5 """
|
|
6
|
2
|
7 # imports
|
1
|
8 import optparse
|
3
|
9 import os
|
2
|
10 import sys
|
3
|
11 import time
|
1
|
12 import wsgiref
|
|
13
|
5
|
14 # module globals
|
|
15 __all__ = ['RequestDumpster']
|
|
16
|
1
|
17 class RequestDumpster(object):
|
5
|
18 """WSGI interface to dump HTTP requests"""
|
1
|
19
|
3
|
20 def __init__(self, directory=None):
|
|
21 if directory is not None and not os.path.isdir(directory):
|
|
22 raise Exception("Not a directory")
|
|
23 self.directory = directory
|
|
24
|
1
|
25 def __call__(self, environ, start_response):
|
|
26 """WSGI"""
|
|
27
|
5
|
28
|
1
|
29 def main(args=sys.argv[1:]):
|
|
30 """CLI"""
|
|
31
|
|
32 # parse command line arguments
|
|
33 parser = optparse.OptionParser(description=__doc__)
|
|
34 parser.add_option('-p', '--port', dest='port',
|
|
35 type='int', default=9555,
|
|
36 help="port to serve on")
|
5
|
37 parser.add_option('-d', '--directory', dest='directory',
|
|
38 help="directory to output requests to")
|
1
|
39 options = parser.parse_args()
|
|
40
|
5
|
41 # instantiate WSGI app
|
|
42 app =
|
|
43
|
1
|
44 # construct url
|
|
45 url = 'http://localhost:{port}/'.format(port=options.port)
|
|
46
|
|
47 if __name__ == '__main__':
|
|
48 main()
|