From 7f9cef011407cd38d618279af04632b982037a17 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Tue, 17 Jan 2012 18:14:47 +0100 Subject: [PATCH] close the chunked fd at the end and honor content chunksizes for a potential first chunk --- requests/models.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/requests/models.py b/requests/models.py index 5d45d7a..2e97694 100644 --- a/requests/models.py +++ b/requests/models.py @@ -615,11 +615,15 @@ class Response(object): def generate_chunked(): resp = self.raw._original_response fp = resp.fp - if resp.chunk_left: - yield fp.read(resp.chunk_left) - fp.read(2) #throw away crlf + if resp.chunk_left is not None: + pending_bytes = resp.chunk_left + while pending_bytes: + chunk = fp.read(min(chunk_size, pending_bytes)) + pending_bytes-=len(chunk) + yield chunk + fp.read(2) # throw away crlf while 1: - #XXX correct line size + #XXX correct line size? (httplib has 64kb, seems insane) pending_bytes = fp.readline(40).strip() pending_bytes = int(pending_bytes, 16) if pending_bytes == 0: @@ -630,6 +634,7 @@ class Response(object): yield chunk fp.read(2) # throw away crlf self._content_consumed = True + fp.close() if getattr(getattr(self.raw, '_original_response', None), 'chunked', False): -- 2.34.1