Skip to content

Commit

Permalink
Dropped ServerHttpProtocol.keep_alive_timeout attr and keep-alive
Browse files Browse the repository at this point in the history
…, `keep_alive_on`, `timeout`, `log` ctor parameters #1606
  • Loading branch information
Nikolay Kim committed Feb 8, 2017
1 parent 95607f1 commit 355857e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 45 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 12 additions & 24 deletions aiohttp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 2 additions & 20 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down

0 comments on commit 355857e

Please sign in to comment.