mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
fix chunked decoding in TeeInput. We need to make sure we didn't have
already in the buffer the last chunk. it fixes socket timeout. Discovered when hacing on it with restkit.
This commit is contained in:
parent
3a2673d52e
commit
ac74d5079d
@ -49,6 +49,15 @@ class TeeInput(object):
|
|||||||
self._len = self._tmp_size()
|
self._len = self._tmp_size()
|
||||||
return self._len
|
return self._len
|
||||||
|
|
||||||
|
def seek(self, offset, whence=0):
|
||||||
|
if self._is_socket:
|
||||||
|
pos = self.tmp.tell()
|
||||||
|
while True:
|
||||||
|
if not self._tee(CHUNK_SIZE):
|
||||||
|
break
|
||||||
|
self.tmp.seek(pos)
|
||||||
|
self.tmp.seek(offset, whence)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
self.tmp.flush()
|
self.tmp.flush()
|
||||||
|
|
||||||
@ -116,14 +125,17 @@ class TeeInput(object):
|
|||||||
|
|
||||||
def _tee(self, length):
|
def _tee(self, length):
|
||||||
""" fetch partial body"""
|
""" fetch partial body"""
|
||||||
while not self.parser.body_eof():
|
while True:
|
||||||
data = read_partial(self.socket, length)
|
|
||||||
self.buf += data
|
|
||||||
chunk, self.buf = self.parser.filter_body(self.buf)
|
chunk, self.buf = self.parser.filter_body(self.buf)
|
||||||
if chunk:
|
if chunk:
|
||||||
self.tmp.write(chunk)
|
self.tmp.write(chunk)
|
||||||
self.tmp.seek(0, os.SEEK_END)
|
self.tmp.seek(0, os.SEEK_END)
|
||||||
return chunk
|
return chunk
|
||||||
|
|
||||||
|
if self.parser.body_eof(): break
|
||||||
|
|
||||||
|
data = read_partial(self.socket, length)
|
||||||
|
self.buf += data
|
||||||
self._finalize()
|
self._finalize()
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@ -131,12 +143,6 @@ class TeeInput(object):
|
|||||||
""" here we wil fetch final trailers
|
""" here we wil fetch final trailers
|
||||||
if any."""
|
if any."""
|
||||||
if self.parser.body_eof():
|
if self.parser.body_eof():
|
||||||
# handle trailing headers
|
|
||||||
if self.parser.is_chunked and self._is_socket:
|
|
||||||
while not self.parser.trailing_header(self.buf):
|
|
||||||
data = read_partial(self.socket, CHUNK_SIZE)
|
|
||||||
if not data: break
|
|
||||||
self.buf += data
|
|
||||||
del self.buf
|
del self.buf
|
||||||
self._is_socket = False
|
self._is_socket = False
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user