changeset 10:db2ab581cedb

works
author Jeff Hammel <k0scist@gmail.com>
date Wed, 16 Dec 2015 12:24:28 -0800
parents 4c613e5840be
children cacab5fb2352
files requestdumpster/dumpster.py
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/requestdumpster/dumpster.py	Wed Dec 16 10:53:34 2015 -0800
+++ b/requestdumpster/dumpster.py	Wed Dec 16 12:24:28 2015 -0800
@@ -10,6 +10,7 @@
 import sys
 import time
 from wsgiref import simple_server
+from webob import Request, Response
 
 # module globals
 __all__ = ['RequestDumpster']
@@ -25,10 +26,19 @@
     def __call__(self, environ, start_response):
         """WSGI"""
 
-        body = """{REQUEST_METHOD} {PATH_INFO} {SERVER_PROTOCOL}""".format(**environ)
+        request = Request(environ)
+        lines = ["{REQUEST_METHOD} {PATH_INFO} {SERVER_PROTOCOL}".format(PATH_INFO=request.path_qs,
+                                                                        REQUEST_METHOD=request.method,
+                                                                        SERVER_PROTOCOL=request.environ['SERVER_PROTOCOL'])]
+        lines.extend(['{0}: {1}'.format(*header)
+                      for header in request.headers.items()])
+        lines.append('')
+        lines.append(request.body)
+        body = '\r\n'.join(lines) + '\r\n'
 
-        start_response('200 OK', [('Content-Type', 'text/plain')])
-        return [body]
+        response = Response(content_type='text/plain',
+                            body=body)
+        return response(environ, start_response)
 
 def main(args=sys.argv[1:]):
     """CLI"""