Skip to content

Commit dd80d35

Browse files
committed
Added ResponseDumpModule
1 parent 04582e2 commit dd80d35

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

devserver/modules/request.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,24 @@ def process_request(self, request):
4646
for var, val in request.META.items():
4747
if var.startswith('HTTP_'):
4848
var = var[5:].replace('_', '-').title()
49-
req += '%s: %s\n' % (self.logger.style.SQL_FIELD(var), val)
49+
req += '%s: %s\n' % (self.logger.style.SQL_KEYWORD(var), val)
5050
if request.META['CONTENT_LENGTH']:
51-
req += '%s: %s\n' % (self.logger.style.SQL_FIELD('Content-Length'), request.META['CONTENT_LENGTH'])
51+
req += '%s: %s\n' % (self.logger.style.SQL_KEYWORD('Content-Length'), request.META['CONTENT_LENGTH'])
5252
if request.POST:
5353
req += '\n%s\n' % self.logger.style.HTTP_INFO(urllib.urlencode(dict((k, v.encode('utf8')) for k, v in request.POST.items())))
5454
if request.FILES:
5555
req += '\n%s\n' % self.logger.style.HTTP_NOT_MODIFIED(urllib.urlencode(request.FILES))
5656
self.logger.info('Full request:\n%s', req)
57+
58+
class ResponseDumpModule(DevServerModule):
59+
"""
60+
Dumps the request headers and variables.
61+
"""
62+
63+
logger_name = 'response'
64+
65+
def process_response(self, request, response):
66+
res = self.logger.style.SQL_FIELD('Status code: %s\n' % response.status_code)
67+
res += '\n'.join(['%s: %s' % (self.logger.style.SQL_FIELD(k), v)
68+
for k, v in response._headers.values()])
69+
self.logger.info('Full response:\n%s', res)

0 commit comments

Comments
 (0)