Commits

Sergey Schetinin committed eaf620e

fix LimitedLengthFile.readline incorrectly detecting disconnect when hinted
https://bitbucket.org/ianb/webob/issue/21

Comments (0)

Files changed (3)

tests/test_in_wsgiref.py

 def _req_int_readline(req):
     try:
         eq(req.body_file.readline(), 'a=b\n')
+        req.body_file.readline()
     except IOError:
         # too early to detect disconnect
         raise AssertionError

tests/test_request_nose.py

         return self.data
 
 
-def test_limite_length_file_repr():
+def test_limited_length_file_repr():
     req = Request.blank('/', POST='x')
     req.body_file_raw = 'dummy'
     req.is_body_seekable = False
                 raise AssertionError("Reading should stop after first empty string")
             self.file_ended = True
         return r
+
+
+def test_disconnect_detection_cgi():
+    data = 'abc'*(1<<20)
+    req = Request.blank('/', POST={'file':('test-file', data)})
+    req.is_body_seekable = False
+    req.POST # should not raise exceptions
+
+def test_disconnect_detection_hinted_readline():
+    data = 'abc'*(1<<20)
+    req = Request.blank('/', POST=data)
+    req.is_body_seekable = False
+    line = req.body_file.readline(1<<16)
+    assert line
+    assert data.startswith(line)
+
         hint = self._normhint(hint)
         r = self.file.readline(hint)
         self.remaining -= len(r)
-        if not r or not r.endswith('\n'):
+        if not r:
             self._check_disconnect()
         return r