diff --git a/gunicorn/http/tee.py b/gunicorn/http/tee.py index 12287932..fdf6cb90 100644 --- a/gunicorn/http/tee.py +++ b/gunicorn/http/tee.py @@ -132,8 +132,6 @@ class TeeInput(object): def _tee(self, length): """ fetch partial body""" while True: - self.buf = read_partial(self.socket, length, self.buf) - chunk, self.buf = self.parser.filter_body(self.buf) if chunk: self.tmp.write(chunk) @@ -144,6 +142,7 @@ class TeeInput(object): if self.parser.body_eof(): break + self.buf = read_partial(self.socket, length, self.buf) self._finalize() return "" diff --git a/gunicorn/util.py b/gunicorn/util.py index 3973e597..85b57d38 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -94,11 +94,13 @@ def close(sock): pass def read_partial(sock, length, buf=None): + tmp_buf = array.array("c", '\0' * length) + l = sock.recv_into(tmp_buf, length) + if not buf: - buf = array.array("c", '\0' * length) - l = sock.recv_into(buf, length) - return buf[:l] - return buf + return tmp_buf[:l] + + return buf + tmp_buf[:l] def write_chunk(sock, data): chunk = "".join(("%X\r\n" % len(data), data, "\r\n"))