From: Ben Darnell Date: Tue, 1 Jul 2014 03:28:10 +0000 (-0400) Subject: Rename the new-in-4.0 gzip parameter to HTTPServer. X-Git-Tag: v4.0.0b2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=159e10d6763819e5a0cd2bb57acb64788a939322;p=thirdparty%2Ftornado.git Rename the new-in-4.0 gzip parameter to HTTPServer. 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. --- diff --git a/docs/releases/next.rst b/docs/releases/next.rst index 2b5e72041..2d99dd1f2 100644 --- a/docs/releases/next.rst +++ b/docs/releases/next.rst @@ -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` ~~~~~~~~~~~~~~~~~~~ diff --git a/docs/web.rst b/docs/web.rst index 277126d6e..175ccff30 100644 --- a/docs/web.rst +++ b/docs/web.rst @@ -149,8 +149,10 @@ * ``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 diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index ae4471fdb..3da59a4df 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -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") diff --git a/tornado/http1connection.py b/tornado/http1connection.py index c43675a1c..72f729d78 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -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) diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 8418b5b26..9bf63c1b8 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -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 diff --git a/tornado/httpserver.py b/tornado/httpserver.py index 277de5884..03b5fc737 100644 --- a/tornado/httpserver.py +++ b/tornado/httpserver.py @@ -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, diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index 06d7ecfa9..99f1c1a78 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -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') diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index f5e5679d9..63a55291b 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -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): diff --git a/tornado/web.py b/tornado/web.py index 506caae75..05305cc9c 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -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