diff --git a/gunicorn/http/parser.py b/gunicorn/http/parser.py index 082f06c8..299d9460 100644 --- a/gunicorn/http/parser.py +++ b/gunicorn/http/parser.py @@ -148,17 +148,20 @@ class Parser(object): chunk_size = int(chunk.pop(0), 16) self.start_offset = i+2 self.chunk_size = chunk_size - if self.chunk_size == 0: - self._chunk_eof = True - return '', data[:self.start_offset] - else: - buf = data[self.start_offset:self.start_offset+self.chunk_size] - end_offset = self.start_offset + self.chunk_size + 2 - # we wait CRLF else return None - if len(data) >= end_offset: - ret = buf, data[end_offset:] - self.chunk_size = 0 + + if self.start_offset: + if self.chunk_size == 0: + self._chunk_eof = True + ret = '', data[:self.start_offset] return ret + else: + buf = data[self.start_offset:self.start_offset+self.chunk_size] + end_offset = self.start_offset + self.chunk_size + 2 + # we wait CRLF else return None + if len(data) >= end_offset: + ret = buf, data[end_offset:] + self.chunk_size = 0 + return ret return '', data def trailing_header(self, data): diff --git a/gunicorn/util.py b/gunicorn/util.py index ee5bc803..f500bb9f 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -92,16 +92,7 @@ def close(sock): pass def read_partial(sock, length): - while True: - try: - ret = select.select([sock.fileno()], [], [], 0) - if ret[0]: break - except select.error, e: - if e[0] == errno.EINTR: - continue - raise - data = sock.recv(length) - return data + return sock.recv(length) def write(sock, data): sock.sendall(data)