Skip to content

Commit

Permalink
Merge pull request #8 from KoleS46/master
Browse files Browse the repository at this point in the history
Check if environ['CONTENT_LENGTH'] not empty.
  • Loading branch information
tseaver committed Jun 3, 2016
2 parents becc540 + c5679ca commit 9d24cd7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion repoze/debug/responselogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_request_info(self, environ):
info['body'] = ''
readargs = []
if 'wsgi.input' in environ:
if 'CONTENT_LENGTH' in environ:
if environ.get('CONTENT_LENGTH') not in (None, ''):
readargs.append(int(environ['CONTENT_LENGTH']))
info['body'] = environ['wsgi.input'].read(*readargs)
try:
Expand Down
17 changes: 17 additions & 0 deletions repoze/debug/tests/test_responselogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ def test_call_contentlengthmissing(self):
self.assertEqual(len(vlogger.logged), 2)
self.assertFalse('WARNING-1' in vlogger.logged[1])

def test_call_contentlengthemptyvalue(self):
body = [b'thebody']
app = DummyApp(body, '200 OK', [('Content-Length', '')])
vlogger = FakeLogger()
tlogger = FakeLogger()
mw = self._makeOne(app, 1, 10, vlogger, tlogger)
environ = _makeEnviron()
environ['CONTENT_LENGTH'] = ''
start_response = FakeStartResponse()
app_iter = mw(environ, start_response)
entry = mw.entries[0]
self.assertEqual(b''.join(app_iter), b'thebody')
self.assertEqual(len(vlogger.logged), 2)
self.assertEqual(entry['response']['content-length'], None)
self.assertEqual(entry['response']['headers'],
[('Content-Length', '')])

def test_call_contentlengthwrong(self):
body = [b'thebody']
app = DummyApp(body, '200 OK', [('Content-Length', '1')])
Expand Down

0 comments on commit 9d24cd7

Please sign in to comment.