@@ -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 )
@@ -187,7 +187,7 @@ def test_partial_reads(self):
187187 self .assertTrue (resp .isclosed ())
188188
189189 def test_partial_readintos (self ):
190- # if we have a lenght , the system knows when to close itself
190+ # if we have a length , the system knows when to close itself
191191 # same behaviour than when we read the whole thing with read()
192192 body = "HTTP/1.1 200 Ok\r \n Content-Length: 4\r \n \r \n Text"
193193 sock = FakeSocket (body )
@@ -203,6 +203,38 @@ def test_partial_readintos(self):
203203 self .assertEqual (bytes (b ), b'xt' )
204204 self .assertTrue (resp .isclosed ())
205205
206+ def test_partial_reads_no_content_length (self ):
207+ # when no length is present, the socket should be gracefully closed when
208+ # all data was read
209+ body = "HTTP/1.1 200 Ok\r \n \r \n Text"
210+ sock = FakeSocket (body )
211+ resp = client .HTTPResponse (sock )
212+ resp .begin ()
213+ self .assertEqual (resp .read (2 ), b'Te' )
214+ self .assertFalse (resp .isclosed ())
215+ self .assertEqual (resp .read (2 ), b'xt' )
216+ self .assertEqual (resp .read (1 ), b'' )
217+ self .assertTrue (resp .isclosed ())
218+
219+ def test_partial_readintos_no_content_length (self ):
220+ # when no length is present, the socket should be gracefully closed when
221+ # all data was read
222+ body = "HTTP/1.1 200 Ok\r \n \r \n Text"
223+ sock = FakeSocket (body )
224+ resp = client .HTTPResponse (sock )
225+ resp .begin ()
226+ b = bytearray (2 )
227+ n = resp .readinto (b )
228+ self .assertEqual (n , 2 )
229+ self .assertEqual (bytes (b ), b'Te' )
230+ self .assertFalse (resp .isclosed ())
231+ n = resp .readinto (b )
232+ self .assertEqual (n , 2 )
233+ self .assertEqual (bytes (b ), b'xt' )
234+ n = resp .readinto (b )
235+ self .assertEqual (n , 0 )
236+ self .assertTrue (resp .isclosed ())
237+
206238 def test_host_port (self ):
207239 # Check invalid host_port
208240
0 commit comments