Mercurial > hg > RequestDumpster
comparison requestdumpster/dumpster.py @ 10:db2ab581cedb
works
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Wed, 16 Dec 2015 12:24:28 -0800 |
| parents | eb260393caef |
| children | d329dfdf6099 |
comparison
equal
deleted
inserted
replaced
| 9:4c613e5840be | 10:db2ab581cedb |
|---|---|
| 8 import argparse | 8 import argparse |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 import time | 11 import time |
| 12 from wsgiref import simple_server | 12 from wsgiref import simple_server |
| 13 from webob import Request, Response | |
| 13 | 14 |
| 14 # module globals | 15 # module globals |
| 15 __all__ = ['RequestDumpster'] | 16 __all__ = ['RequestDumpster'] |
| 16 | 17 |
| 17 class RequestDumpster(object): | 18 class RequestDumpster(object): |
| 23 self.directory = directory | 24 self.directory = directory |
| 24 | 25 |
| 25 def __call__(self, environ, start_response): | 26 def __call__(self, environ, start_response): |
| 26 """WSGI""" | 27 """WSGI""" |
| 27 | 28 |
| 28 body = """{REQUEST_METHOD} {PATH_INFO} {SERVER_PROTOCOL}""".format(**environ) | 29 request = Request(environ) |
| 30 lines = ["{REQUEST_METHOD} {PATH_INFO} {SERVER_PROTOCOL}".format(PATH_INFO=request.path_qs, | |
| 31 REQUEST_METHOD=request.method, | |
| 32 SERVER_PROTOCOL=request.environ['SERVER_PROTOCOL'])] | |
| 33 lines.extend(['{0}: {1}'.format(*header) | |
| 34 for header in request.headers.items()]) | |
| 35 lines.append('') | |
| 36 lines.append(request.body) | |
| 37 body = '\r\n'.join(lines) + '\r\n' | |
| 29 | 38 |
| 30 start_response('200 OK', [('Content-Type', 'text/plain')]) | 39 response = Response(content_type='text/plain', |
| 31 return [body] | 40 body=body) |
| 41 return response(environ, start_response) | |
| 32 | 42 |
| 33 def main(args=sys.argv[1:]): | 43 def main(args=sys.argv[1:]): |
| 34 """CLI""" | 44 """CLI""" |
| 35 | 45 |
| 36 # parse command line arguments | 46 # parse command line arguments |
