]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Rename the new-in-4.0 gzip parameter to HTTPServer.
authorBen Darnell <ben@bendarnell.com>
Tue, 1 Jul 2014 03:28:10 +0000 (23:28 -0400)
committerBen Darnell <ben@bendarnell.com>
Tue, 1 Jul 2014 03:32:50 +0000 (23:32 -0400)
All the gzip-related parameters are now explicit about whether
they compress or decompress and whether they apply to requests or
responses.  For all the parameters that existed prior to 4.0
the old names are accepted as well, but for the new ones in 4.0
we don't need to worry about backwards-compatibility.

This is motivated by the potential confusion around the use of
gzip as a parameter to the Application constructor to indicate
compression of responses and to the HTTPServer constructor to
indicate decompression of requests.

docs/releases/next.rst
docs/web.rst
tornado/curl_httpclient.py
tornado/http1connection.py
tornado/httpclient.py
tornado/httpserver.py
tornado/simple_httpclient.py
tornado/test/httpserver_test.py
tornado/web.py

index 2b5e720411a8504e505ef96d323e8e48ce51beeb..2d99dd1f28a8f92a05c1b0963b1a641271f2e5ed 100644 (file)
@@ -100,6 +100,8 @@ Other notes
   now works on Python 3.
 * Fixed a memory leak in `.AsyncHTTPClient` shutdown that affected
   applications that created many HTTP clients and IOLoops.
+* New client request parameter ``decompress_response`` replaces
+  the existing ``use_gzip`` parameter; both names are accepted.
 
 `tornado.httpserver`
 ~~~~~~~~~~~~~~~~~~~~
@@ -109,8 +111,8 @@ Other notes
 * HTTP implementation has been unified with ``tornado.simple_httpclient``
   in `tornado.http1connection`.
 * Now supports ``Transfer-Encoding: chunked`` for request bodies.
-* Now supports ``Content-Encoding: gzip`` for request bodies if ``gzip=True``
-  is passed to the `.HTTPServer` constructor.
+* Now supports ``Content-Encoding: gzip`` for request bodies if
+  ``decompress_request=True`` is passed to the `.HTTPServer` constructor.
 * The ``connection`` attribute of `.HTTPServerRequest` is now documented
   for public use; applications are expected to write their responses
   via the `.HTTPConnection` interface.
@@ -265,6 +267,8 @@ Other notes
 * `.RequestHandler.flush` now returns a `.Future` if no callback is given.
 * ``HEAD`` requests in `.StaticFileHandler` no longer read the entire file.
 * `.StaticFileHandler` now streams response bodies to the client.
+* New setting ``compress_response`` replaces the existing ``gzip``
+  setting; both names are accepted.
 
 `tornado.websocket`
 ~~~~~~~~~~~~~~~~~~~
index 277126d6e80a6344467ae421426272c9d93af49a..175ccff300bcc0380567c2bad92c154e970f7c89 100644 (file)
          * ``default_handler_class`` and ``default_handler_args``:
            This handler will be used if no other match is found;
            use this to implement custom 404 pages (new in Tornado 3.2).
-         * ``gzip``: If ``True``, responses in textual formats will be
-           gzipped automatically.
+         * ``compress_response``: If ``True``, responses in textual formats
+           will be compressed automatically.  New in Tornado 4.0.
+         * ``gzip``: Deprecated alias for ``compress_response`` since
+           Tornado 4.0.
          * ``log_function``: This function will be called at the end
            of every request to log the result (with one argument, the
            `RequestHandler` object).  The default implementation
index ae4471fdb9730a43564c3d8f79ac129424625edb..3da59a4df94d031d5e0428ff649449bbb8b243eb 100644 (file)
@@ -332,7 +332,7 @@ def _curl_setup_request(curl, request, buffer, headers):
         curl.setopt(pycurl.USERAGENT, "Mozilla/5.0 (compatible; pycurl)")
     if request.network_interface:
         curl.setopt(pycurl.INTERFACE, request.network_interface)
-    if request.use_gzip:
+    if request.decompress_response:
         curl.setopt(pycurl.ENCODING, "gzip,deflate")
     else:
         curl.setopt(pycurl.ENCODING, "none")
index c43675a1c392bae82ed0bb5df2c99f0d70fa2099..72f729d784c28aa9d5ea2dd3de81fd26b84ef849 100644 (file)
@@ -56,7 +56,7 @@ class HTTP1ConnectionParameters(object):
     """
     def __init__(self, no_keep_alive=False, chunk_size=None,
                  max_header_size=None, header_timeout=None, max_body_size=None,
-                 body_timeout=None, use_gzip=False):
+                 body_timeout=None, decompress=False):
         """
         :arg bool no_keep_alive: If true, always close the connection after
             one request.
@@ -65,7 +65,8 @@ class HTTP1ConnectionParameters(object):
         :arg float header_timeout: how long to wait for all headers (seconds)
         :arg int max_body_size: maximum amount of data for body
         :arg float body_timeout: how long to wait while reading body (seconds)
-        :arg bool use_gzip: if true, decode incoming ``Content-Encoding: gzip``
+        :arg bool decompress: if true, decode incoming
+            ``Content-Encoding: gzip``
         """
         self.no_keep_alive = no_keep_alive
         self.chunk_size = chunk_size or 65536
@@ -73,7 +74,7 @@ class HTTP1ConnectionParameters(object):
         self.header_timeout = header_timeout
         self.max_body_size = max_body_size
         self.body_timeout = body_timeout
-        self.use_gzip = use_gzip
+        self.decompress = decompress
 
 
 class HTTP1Connection(httputil.HTTPConnection):
@@ -141,7 +142,7 @@ class HTTP1Connection(httputil.HTTPConnection):
         Returns a `.Future` that resolves to None after the full response has
         been read.
         """
-        if self.params.use_gzip:
+        if self.params.decompress:
             delegate = _GzipMessageDelegate(delegate, self.params.chunk_size)
         return self._read_message(delegate)
 
index 8418b5b2648f6d56b75eb586c465ff9138dce5e5..9bf63c1b843e68ca74770cab651d71b506533b21 100644 (file)
@@ -279,7 +279,7 @@ class HTTPRequest(object):
         request_timeout=20.0,
         follow_redirects=True,
         max_redirects=5,
-        use_gzip=True,
+        decompress_response=True,
         proxy_password='',
         allow_nonstandard_methods=False,
         validate_cert=True)
@@ -296,7 +296,7 @@ class HTTPRequest(object):
                  validate_cert=None, ca_certs=None,
                  allow_ipv6=None,
                  client_key=None, client_cert=None, body_producer=None,
-                 expect_100_continue=False):
+                 expect_100_continue=False, decompress_response=None):
         r"""All parameters except ``url`` are optional.
 
         :arg string url: URL to fetch
@@ -330,7 +330,11 @@ class HTTPRequest(object):
            or return the 3xx response?
         :arg int max_redirects: Limit for ``follow_redirects``
         :arg string user_agent: String to send as ``User-Agent`` header
-        :arg bool use_gzip: Request gzip encoding from the server
+        :arg bool decompress_response: Request a compressed response from
+           the server and decompress it after downloading.  Default is True.
+           New in Tornado 4.0.
+        :arg bool use_gzip: Deprecated alias for ``decompress_response``
+           since Tornado 4.0.
         :arg string network_interface: Network interface to use for request.
            ``curl_httpclient`` only; see note below.
         :arg callable streaming_callback: If set, ``streaming_callback`` will
@@ -373,7 +377,6 @@ class HTTPRequest(object):
            before sending the request body.  Only supported with
            simple_httpclient.
 
-
         .. note::
 
             When using ``curl_httpclient`` certain options may be
@@ -414,7 +417,10 @@ class HTTPRequest(object):
         self.follow_redirects = follow_redirects
         self.max_redirects = max_redirects
         self.user_agent = user_agent
-        self.use_gzip = use_gzip
+        if decompress_response is not None:
+            self.decompress_response = decompress_response
+        else:
+            self.decompress_response = use_gzip
         self.network_interface = network_interface
         self.streaming_callback = streaming_callback
         self.header_callback = header_callback
index 277de5884cbfea1341be02d6971218e6470a793d..03b5fc7379ceb435c61f21380c689061f776a0cf 100644 (file)
@@ -129,13 +129,14 @@ class HTTPServer(TCPServer, httputil.HTTPServerConnectionDelegate):
        way other than `tornado.netutil.bind_sockets`.
 
     .. versionchanged:: 4.0
-       Added ``gzip``, ``chunk_size``, ``max_header_size``,
+       Added ``decompress_request``, ``chunk_size``, ``max_header_size``,
        ``idle_connection_timeout``, ``body_timeout``, ``max_body_size``
        arguments.  Added support for `.HTTPServerConnectionDelegate`
        instances as ``request_callback``.
     """
     def __init__(self, request_callback, no_keep_alive=False, io_loop=None,
-                 xheaders=False, ssl_options=None, protocol=None, gzip=False,
+                 xheaders=False, ssl_options=None, protocol=None,
+                 decompress_request=False,
                  chunk_size=None, max_header_size=None,
                  idle_connection_timeout=None, body_timeout=None,
                  max_body_size=None, max_buffer_size=None):
@@ -144,7 +145,7 @@ class HTTPServer(TCPServer, httputil.HTTPServerConnectionDelegate):
         self.xheaders = xheaders
         self.protocol = protocol
         self.conn_params = HTTP1ConnectionParameters(
-            use_gzip=gzip,
+            decompress=decompress_request,
             chunk_size=chunk_size,
             max_header_size=max_header_size,
             header_timeout=idle_connection_timeout or 3600,
index 06d7ecfa9fb8ba6213976fce9fe90f498a681e82..99f1c1a782cc9e9c2685417e6d436f4d973e1684 100644 (file)
@@ -338,7 +338,7 @@ class _HTTPConnection(httputil.HTTPMessageDelegate):
         if (self.request.method == "POST" and
                 "Content-Type" not in self.request.headers):
             self.request.headers["Content-Type"] = "application/x-www-form-urlencoded"
-        if self.request.use_gzip:
+        if self.request.decompress_response:
             self.request.headers["Accept-Encoding"] = "gzip"
         req_path = ((self.parsed.path or '/') +
                     (('?' + self.parsed.query) if self.parsed.query else ''))
@@ -348,7 +348,7 @@ class _HTTPConnection(httputil.HTTPMessageDelegate):
             HTTP1ConnectionParameters(
                 no_keep_alive=True,
                 max_header_size=self.max_header_size,
-                use_gzip=self.request.use_gzip),
+                decompress=self.request.decompress_response),
             self._sockaddr)
         start_line = httputil.RequestStartLine(self.request.method,
                                                req_path, 'HTTP/1.1')
index f5e5679d9e4d2aac5598624ddd80d4ad4196c55a..63a55291b900f8cf410b36cf6b0f2b2dfb888a27 100644 (file)
@@ -736,7 +736,7 @@ class GzipBaseTest(object):
 
 class GzipTest(GzipBaseTest, AsyncHTTPTestCase):
     def get_httpserver_options(self):
-        return dict(gzip=True)
+        return dict(decompress_request=True)
 
     def test_gzip(self):
         response = self.post_gzip('foo=bar')
@@ -764,7 +764,7 @@ class StreamingChunkSizeTest(AsyncHTTPTestCase):
         return SimpleAsyncHTTPClient(io_loop=self.io_loop)
 
     def get_httpserver_options(self):
-        return dict(chunk_size=self.CHUNK_SIZE, gzip=True)
+        return dict(chunk_size=self.CHUNK_SIZE, decompress_request=True)
 
     class MessageDelegate(HTTPMessageDelegate):
         def __init__(self, connection):
index 506caae7538189aab6ccd7a5935767d0336d05c2..05305cc9ced292aa0081c9e1705d0e29f186757b 100644 (file)
@@ -1627,7 +1627,7 @@ class Application(httputil.HTTPServerConnectionDelegate):
                  **settings):
         if transforms is None:
             self.transforms = []
-            if settings.get("gzip"):
+            if settings.get("compress_response") or settings.get("gzip"):
                 self.transforms.append(GZipContentEncoding)
         else:
             self.transforms = transforms