From 355857e551af0b45edac3dd0ec650dc5028b1e4d Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 8 Feb 2017 13:26:54 -0800 Subject: [PATCH] Dropped `ServerHttpProtocol.keep_alive_timeout` attr and `keep-alive`, `keep_alive_on`, `timeout`, `log` ctor parameters #1606 --- CHANGES.rst | 3 +++ aiohttp/server.py | 36 ++++++++++++------------------------ aiohttp/worker.py | 2 +- tests/test_server.py | 22 ++-------------------- 4 files changed, 18 insertions(+), 45 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index c8edc94d679..42c5846b3c1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -17,3 +17,6 @@ CHANGES aiohttp.put(), aiohttp.patch(), aiohttp.delete(), and aiohttp.ws_connect() #1593 - Dropped: `aiohttp.web.WebSocketResponse.receive_msg()` #1605 + +- Dropped: `ServerHttpProtocol.keep_alive_timeout` attr and + `keep-alive`, `keep_alive_on`, `timeout`, `log` ctor parameters #1606 diff --git a/aiohttp/server.py b/aiohttp/server.py index aec1a0b83a6..ce22e4336b6 100644 --- a/aiohttp/server.py +++ b/aiohttp/server.py @@ -4,13 +4,12 @@ import http.server import socket import traceback -import warnings from contextlib import suppress from html import escape as html_escape import aiohttp from aiohttp import errors, hdrs, helpers, streams -from aiohttp.helpers import TimeService, _get_kwarg, ensure_future +from aiohttp.helpers import TimeService, ensure_future from aiohttp.log import access_logger, server_logger __all__ = ('ServerHttpProtocol',) @@ -102,26 +101,19 @@ def __init__(self, *, loop=None, **kwargs): # process deprecated params - logger = _get_kwarg(kwargs, 'log', 'logger', logger) - - tcp_keepalive = _get_kwarg(kwargs, 'keep_alive_on', - 'tcp_keepalive', tcp_keepalive) - - keepalive_timeout = _get_kwarg(kwargs, 'keep_alive', - 'keepalive_timeout', keepalive_timeout) - - slow_request_timeout = _get_kwarg(kwargs, 'timeout', - 'slow_request_timeout', - slow_request_timeout) + logger = kwargs.get('logger', logger) super().__init__( loop=loop, disconnect_error=errors.ClientDisconnectedError, **kwargs) self._loop = loop if loop is not None else asyncio.get_event_loop() - self._time_service = ( - time_service if time_service is not None - else TimeService(self._loop)) + if time_service is not None: + self._time_service_owner = False + self._time_service = time_service + else: + self._time_service_owner = True + self._time_service = TimeService(self._loop) self._tcp_keepalive = tcp_keepalive self._keepalive_timeout = keepalive_timeout self._slow_request_timeout = slow_request_timeout @@ -147,13 +139,6 @@ def __init__(self, *, loop=None, def time_service(self): return self._time_service - @property - def keep_alive_timeout(self): - warnings.warn("Use keepalive_timeout property instead", - DeprecationWarning, - stacklevel=2) - return self._keepalive_timeout - @property def keepalive_timeout(self): return self._keepalive_timeout @@ -194,7 +179,8 @@ def connection_lost(self, exc): if self._request_handler is not None: self._request_handler.cancel() - self._time_service = None + if self._time_service_owner: + self._time_service.close() def data_received(self, data): super().data_received(data) @@ -365,6 +351,7 @@ def handle_error(self, status=500, message=None, response = aiohttp.Response(self.writer, status, close=True) response.add_header(hdrs.CONTENT_TYPE, 'text/html; charset=utf-8') response.add_header(hdrs.CONTENT_LENGTH, str(len(html))) + response.add_header(hdrs.DATE, self._time_service.strtime()) if headers is not None: for name, value in headers: response.add_header(name, value) @@ -399,6 +386,7 @@ def handle_request(self, message, payload): response.add_header(hdrs.CONTENT_TYPE, 'text/plain') response.add_header(hdrs.CONTENT_LENGTH, str(len(body))) + response.add_header(hdrs.DATE, self._time_service.strtime()) response.send_headers() response.write(body) drain = response.write_eof() diff --git a/aiohttp/worker.py b/aiohttp/worker.py index a6838ab524f..8f8c0a3badf 100644 --- a/aiohttp/worker.py +++ b/aiohttp/worker.py @@ -241,7 +241,7 @@ def __call__(self): loop=self._loop, logger=self.worker.log, debug=self.worker.log.loglevel == logging.DEBUG, - keep_alive=self.worker.cfg.keepalive, + keepalive_timeout=self.worker.cfg.keepalive, access_log=self.worker.log.access_log, access_log_format=self.access_log_format) diff --git a/tests/test_server.py b/tests/test_server.py index dc2ee97bfca..63208e5cca6 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -542,7 +542,7 @@ def test_handle_error_no_handle_task(srv): def test_keep_alive(make_srv, loop): - srv = make_srv(keep_alive=0.1) + srv = make_srv(keepalive_timeout=0.1) transport = mock.Mock() closed = False @@ -587,7 +587,7 @@ def test_keep_alive_close_existing(make_srv, loop): def test_srv_process_request_without_timeout(make_srv, loop): transport = mock.Mock() - srv = make_srv(timeout=0) + srv = make_srv(slow_request_timeout=0) srv.connection_made(transport) srv.reader.feed_data( @@ -607,24 +607,6 @@ def test_keep_alive_timeout_nondefault(make_srv): assert 10 == srv.keepalive_timeout -def test_keep_alive_timeout_deprecated(make_srv): - with pytest.warns(DeprecationWarning) as ctx: - make_srv(keep_alive=10) - assert len(ctx) == 1 - expected = "keep_alive is deprecated, use keepalive_timeout instead" - assert ctx[0].message.args == (expected,) - - -def test_keep_alive_timeout_deprecated2(make_srv): - srv = make_srv(keepalive_timeout=10) - - with pytest.warns(DeprecationWarning) as ctx: - assert 10 == srv.keep_alive_timeout - assert len(ctx) == 1 - expected = "Use keepalive_timeout property instead" - assert ctx[0].message.args == (expected,) - - def test_supports_connect_method(srv, loop): transport = mock.Mock() srv.connection_made(transport)