]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Handle redirects before processing data and sending it to streaming_callback.
authorBen Darnell <ben@bendarnell.com>
Thu, 5 Jan 2012 08:27:45 +0000 (00:27 -0800)
committerBen Darnell <ben@bendarnell.com>
Thu, 5 Jan 2012 08:27:45 +0000 (00:27 -0800)
Previously, if you were using follow_redirects and streaming_callback
and hit a redirect with a non-empty body, that body would be passed
to streaming_callback as well.

As a side effect, this improves compatibility with some misconfigured
sites that send Content-Encoding: gzip on redirects without actually
compressing the body.

tornado/httpclient.py
tornado/simple_httpclient.py

index 443657c038609b0ea4fbf8ee13a7e49ea1330dec..a6ad4fa13939437014f6d12c3858a036aaf8e6f1 100644 (file)
@@ -396,7 +396,8 @@ def main():
     for arg in args:
         try:
             response = client.fetch(arg,
-                                    follow_redirects=options.follow_redirects)
+                                    follow_redirects=options.follow_redirects
+                                    )
         except HTTPError, e:
             if e.response is not None:
                 response = e.response
index 15773bb3bff2d13d0031508a35e39318f73b7861..ce2762f1d36f526be16dee0ee30cb9cb3443cee5 100644 (file)
@@ -355,16 +355,6 @@ class _HTTPConnection(object):
         if self._timeout is not None:
             self.io_loop.remove_timeout(self._timeout)
             self._timeout = None
-        if self._decompressor:
-            data = self._decompressor.decompress(data)
-        if self.request.streaming_callback:
-            if self.chunks is None:
-                # if chunks is not None, we already called streaming_callback
-                # in _on_chunk_data
-                self.request.streaming_callback(data)
-            buffer = BytesIO()
-        else:
-            buffer = BytesIO(data) # TODO: don't require one big string?
         original_request = getattr(self.request, "original_request",
                                    self.request)
         if (self.request.follow_redirects and
@@ -382,6 +372,16 @@ class _HTTPConnection(object):
             self.client.fetch(new_request, final_callback)
             self.stream.close()
             return
+        if self._decompressor:
+            data = self._decompressor.decompress(data)
+        if self.request.streaming_callback:
+            if self.chunks is None:
+                # if chunks is not None, we already called streaming_callback
+                # in _on_chunk_data
+                self.request.streaming_callback(data)
+            buffer = BytesIO()
+        else:
+            buffer = BytesIO(data) # TODO: don't require one big string?
         response = HTTPResponse(original_request,
                                 self.code, headers=self.headers,
                                 request_time=time.time() - self.start_time,