From c2f12a4977836245cdbe3b4a444bc35ffbe0fb02 Mon Sep 17 00:00:00 2001 From: benoitc Date: Sun, 28 Feb 2010 21:10:32 +0100 Subject: [PATCH] should fix _ensure_length in tee. while I'm here fix chunked response. --- gunicorn/http/parser.py | 6 ++---- gunicorn/http/response.py | 2 +- gunicorn/http/tee.py | 4 +++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gunicorn/http/parser.py b/gunicorn/http/parser.py index a182bd2e..cb8c9bef 100644 --- a/gunicorn/http/parser.py +++ b/gunicorn/http/parser.py @@ -37,13 +37,12 @@ class Parser(object): with new headers. """ - ld = len("\r\n\r\n") s = "".join(buf) i = s.find("\r\n\r\n") if i != -1: if i > 0: r = s[:i] - pos = i+ld + pos = i+4 return self.finalize_headers(headers, r, pos) return -1 @@ -119,8 +118,7 @@ class Parser(object): @property def is_chunked(self): """ is TE: chunked ?""" - transfert_encoding = self.headers_dict.get('Transfer-Encoding', False) - return (transfert_encoding == "chunked") + return (self.headers_dict.get('Transfer-Encoding') == "chunked") @property def content_len(self): diff --git a/gunicorn/http/response.py b/gunicorn/http/response.py index f2813e9e..8ba50469 100644 --- a/gunicorn/http/response.py +++ b/gunicorn/http/response.py @@ -3,7 +3,7 @@ # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. -from gunicorn.util import http_date, write, close +from gunicorn.util import close, http_date, write, write_chunk class Response(object): diff --git a/gunicorn/http/tee.py b/gunicorn/http/tee.py index 05b25909..18434d2a 100644 --- a/gunicorn/http/tee.py +++ b/gunicorn/http/tee.py @@ -155,7 +155,9 @@ class TeeInput(object): def _ensure_length(self, buf, length): if not buf or not self._len: return buf - while len(buf) < length and self.len != self.tmp.tell(): + while True: + if len(buf) >= length: + break data = self._tee(length - len(buf)) if not data: break buf += data