diff --git a/docs/sanic/config.md b/docs/sanic/config.md index 2bbce5d0..a93d2cf1 100644 --- a/docs/sanic/config.md +++ b/docs/sanic/config.md @@ -83,4 +83,4 @@ Out of the box there are just a few predefined values which can be overwritten w | ----------------- | --------- | --------------------------------- | | REQUEST_MAX_SIZE | 100000000 | How big a request may be (bytes) | | REQUEST_TIMEOUT | 60 | How long a request can take (sec) | - | NO_KEEP_ALIVE | False | Disable keep-alive | + | KEEP_ALIVE | True | Disables keep-alive when False | diff --git a/sanic/app.py b/sanic/app.py index b126fc5d..1cb6554f 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -679,7 +679,7 @@ class Sanic: 'error_handler': self.error_handler, 'request_timeout': self.config.REQUEST_TIMEOUT, 'request_max_size': self.config.REQUEST_MAX_SIZE, - 'no_keep_alive': self.config.NO_KEEP_ALIVE, + 'keep_alive': self.config.KEEP_ALIVE, 'loop': loop, 'register_sys_signals': register_sys_signals, 'backlog': backlog diff --git a/sanic/config.py b/sanic/config.py index ca08d8b0..4c128b4b 100644 --- a/sanic/config.py +++ b/sanic/config.py @@ -6,7 +6,7 @@ SANIC_PREFIX = 'SANIC_' class Config(dict): - def __init__(self, defaults=None, load_env=True, no_keep_alive=False): + def __init__(self, defaults=None, load_env=True, keep_alive=True): super().__init__(defaults or {}) self.LOGO = """ ▄▄▄▄▄ @@ -31,7 +31,7 @@ class Config(dict): """ self.REQUEST_MAX_SIZE = 100000000 # 100 megababies self.REQUEST_TIMEOUT = 60 # 60 seconds - self.NO_KEEP_ALIVE = no_keep_alive + self.KEEP_ALIVE = keep_alive if load_env: self.load_environment_vars() diff --git a/sanic/server.py b/sanic/server.py index 9edda142..33763bbb 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -71,7 +71,7 @@ class HttpProtocol(asyncio.Protocol): def __init__(self, *, loop, request_handler, error_handler, signal=Signal(), connections=set(), request_timeout=60, request_max_size=None, request_class=None, - no_keep_alive=False): + keep_alive=True): self.loop = loop self.transport = None self.request = None @@ -89,11 +89,11 @@ class HttpProtocol(asyncio.Protocol): self._timeout_handler = None self._last_request_time = None self._request_handler_task = None - self._no_keep_alive = no_keep_alive + self._keep_alive = keep_alive @property def keep_alive(self): - return (not self._no_keep_alive + return (self._keep_alive and not self.signal.stopped and self.parser.should_keep_alive()) @@ -326,7 +326,7 @@ def serve(host, port, request_handler, error_handler, before_start=None, request_timeout=60, ssl=None, sock=None, request_max_size=None, reuse_port=False, loop=None, protocol=HttpProtocol, backlog=100, register_sys_signals=True, run_async=False, connections=None, - signal=Signal(), request_class=None, no_keep_alive=False): + signal=Signal(), request_class=None, keep_alive=True): """Start asynchronous HTTP Server on an individual process. :param host: Address to host on @@ -374,7 +374,7 @@ def serve(host, port, request_handler, error_handler, before_start=None, request_timeout=request_timeout, request_max_size=request_max_size, request_class=request_class, - no_keep_alive=no_keep_alive, + keep_alive=keep_alive, ) server_coroutine = loop.create_server(