@@ -175,7 +175,7 @@ def test_bad_status_repr(self):
175175 self .assertEqual (repr (exc ), '''BadStatusLine("\' \' ",)''' )
176176
177177 def test_partial_reads (self ):
178- # if we have a lenght , the system knows when to close itself
178+ # if we have a length , the system knows when to close itself
179179 # same behaviour than when we read the whole thing with read()
180180 body = "HTTP/1.1 200 Ok\r \n Content-Length: 4\r \n \r \n Text"
181181 sock = FakeSocket (body )
@@ -186,6 +186,19 @@ def test_partial_reads(self):
186186 self .assertEqual (resp .read (2 ), b'xt' )
187187 self .assertTrue (resp .isclosed ())
188188
189+ def test_partial_reads_no_content_length (self ):
190+ # when no length is present, the socket should be gracefully closed when
191+ # all data was read
192+ body = "HTTP/1.1 200 Ok\r \n \r \n Text"
193+ sock = FakeSocket (body )
194+ resp = client .HTTPResponse (sock )
195+ resp .begin ()
196+ self .assertEqual (resp .read (2 ), b'Te' )
197+ self .assertFalse (resp .isclosed ())
198+ self .assertEqual (resp .read (2 ), b'xt' )
199+ self .assertEqual (resp .read (1 ), b'' )
200+ self .assertTrue (resp .isclosed ())
201+
189202 def test_host_port (self ):
190203 # Check invalid host_port
191204
0 commit comments