Commit 5df4cef9 authored by Denis Bilenko's avatar Denis Bilenko

Fix #303: 'requestline' AttributeError in pywsgi

Close #304: original PR by Neil Chintomby.
parent d54a13df
...@@ -291,21 +291,22 @@ class WSGIHandler(object): ...@@ -291,21 +291,22 @@ class WSGIHandler(object):
return return
try: try:
raw_requestline = self.read_requestline() self.requestline = self.read_requestline()
except socket.error: except socket.error:
# "Connection reset by peer" or other socket errors aren't interesting here # "Connection reset by peer" or other socket errors aren't interesting here
return return
if not raw_requestline: if not self.requestline:
return return
self.response_length = 0 self.response_length = 0
if len(raw_requestline) >= MAX_REQUEST_LINE: if len(self.requestline) >= MAX_REQUEST_LINE:
return ('414', _REQUEST_TOO_LONG_RESPONSE) return ('414', _REQUEST_TOO_LONG_RESPONSE)
try: try:
if not self.read_request(raw_requestline): # for compatibility with older versions of pywsgi, we pass self.requestline as an argument there
if not self.read_request(self.requestline):
return ('400', _BAD_REQUEST_RESPONSE) return ('400', _BAD_REQUEST_RESPONSE)
except Exception: except Exception:
ex = sys.exc_info()[1] ex = sys.exc_info()[1]
...@@ -473,7 +474,7 @@ class WSGIHandler(object): ...@@ -473,7 +474,7 @@ class WSGIHandler(object):
return '%s - - [%s] "%s" %s %s %s' % ( return '%s - - [%s] "%s" %s %s %s' % (
self.client_address[0], self.client_address[0],
now, now,
self.requestline, getattr(self, 'requestline', ''),
(getattr(self, 'status', None) or '000').split()[0], (getattr(self, 'status', None) or '000').split()[0],
length, length,
delta) delta)
......
...@@ -1218,6 +1218,20 @@ class TestInputRaw(greentest.BaseTestCase): ...@@ -1218,6 +1218,20 @@ class TestInputRaw(greentest.BaseTestCase):
i = self.make_input("2\r\n1", chunked_input=True) i = self.make_input("2\r\n1", chunked_input=True)
self.assertRaises(IOError, i.readline) self.assertRaises(IOError, i.readline)
class Test414(TestCase):
@staticmethod
def application(env, start_response):
raise AssertionError('should not get there')
def test(self):
fd = self.makefile()
longline = 'x' * 20000
fd.write('''GET /%s HTTP/1.0\r\nHello: world\r\n\r\n''' % longline)
read_http(fd, code=414, version='1.0')
del CommonTests del CommonTests
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment