File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,7 @@ def close(self):
168
168
169
169
def iterchunks (self ):
170
170
assert self .chunked
171
+ buffer = b''
171
172
while True :
172
173
if self .resp .isclosed ():
173
174
break
@@ -178,8 +179,20 @@ def iterchunks(self):
178
179
self ._release_conn ()
179
180
break
180
181
chunk = self .resp .fp .read (chunksz )
181
- for ln in chunk .splitlines ():
182
- yield ln
182
+
183
+ for ln in chunk .splitlines (True ):
184
+ end = (ln == b'\n ' ) and not buffer # end of response
185
+
186
+ if ln and not end :
187
+ if ln .endswith (b'\n ' ):
188
+ # end of a document
189
+ yield buffer + ln
190
+ buffer = b''
191
+ else :
192
+ # a break inside a document --> add to buffer and reuse
193
+ # later
194
+ buffer += ln
195
+
183
196
self .resp .fp .read (2 ) #crlf
184
197
185
198
Original file line number Diff line number Diff line change @@ -64,11 +64,11 @@ def close(self):
64
64
def isclosed (self ):
65
65
return len (self .fp .getvalue ()) == self .fp .tell ()
66
66
67
- data = b'foobarbaz'
67
+ data = b'foobarbaz\n '
68
68
data = b'\n ' .join ([hex (len (data ))[2 :].encode ('utf-8' ), data ])
69
69
response = http .ResponseBody (TestHttpResp (util .StringIO (data )),
70
70
None , None , None )
71
- self .assertEqual (list (response .iterchunks ()), [b'foobarbaz' ])
71
+ self .assertEqual (list (response .iterchunks ()), [b'foobarbaz\n ' ])
72
72
self .assertEqual (list (response .iterchunks ()), [])
73
73
74
74
You can’t perform that action at this time.
0 commit comments