From: Ronny Pfannschmidt Date: Tue, 17 Jan 2012 17:14:47 +0000 (+0100) Subject: close the chunked fd at the end and honor content chunksizes for a potential first... X-Git-Tag: v0.9.2~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7f9cef011407cd38d618279af04632b982037a17;p=services%2Fpython-requests.git close the chunked fd at the end and honor content chunksizes for a potential first chunk --- 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):