Skip to content

Commit 686dec7

Browse files
committed
Make AppRunner's configuration options available in run_app() (aio-libs#11633)
(cherry picked from commit b1bd65d)
1 parent 2fd4b40 commit 686dec7

4 files changed

Lines changed: 27 additions & 27 deletions

File tree

CHANGES/11633.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make configuration options in ``AppRunner`` also available in ``run_app()``
2+
-- by :user:`Cycloctane`.

aiohttp/web.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -297,35 +297,20 @@ async def _run_app(
297297
port: int | None = None,
298298
path: PathLike | TypingIterable[PathLike] | None = None,
299299
sock: socket.socket | TypingIterable[socket.socket] | None = None,
300-
shutdown_timeout: float = 60.0,
301-
keepalive_timeout: float = 75.0,
302300
ssl_context: SSLContext | None = None,
303301
print: Callable[..., None] | None = print,
304302
backlog: int = 128,
305-
access_log_class: type[AbstractAccessLogger] = AccessLogger,
306-
access_log_format: str = AccessLogger.LOG_FORMAT,
307-
access_log: logging.Logger | None = access_logger,
308-
handle_signals: bool = True,
309303
reuse_address: bool | None = None,
310304
reuse_port: bool | None = None,
311-
handler_cancellation: bool = False,
305+
**kwargs: Any, # TODO(PY311): Use Unpack
312306
) -> None:
313307
# An internal function to actually do all dirty job for application running
314308
if asyncio.iscoroutine(app):
315309
app = await app
316310

317311
app = cast(Application, app)
318312

319-
runner = AppRunner(
320-
app,
321-
handle_signals=handle_signals,
322-
access_log_class=access_log_class,
323-
access_log_format=access_log_format,
324-
access_log=access_log,
325-
keepalive_timeout=keepalive_timeout,
326-
shutdown_timeout=shutdown_timeout,
327-
handler_cancellation=handler_cancellation,
328-
)
313+
runner = AppRunner(app, **kwargs)
329314

330315
await runner.setup()
331316

@@ -472,6 +457,7 @@ def run_app(
472457
reuse_port: bool | None = None,
473458
handler_cancellation: bool = False,
474459
loop: asyncio.AbstractEventLoop | None = None,
460+
**kwargs: Any,
475461
) -> None:
476462
"""Run an app locally"""
477463
if loop is None:
@@ -503,6 +489,7 @@ def run_app(
503489
reuse_address=reuse_address,
504490
reuse_port=reuse_port,
505491
handler_cancellation=handler_cancellation,
492+
**kwargs,
506493
)
507494
)
508495

docs/web_reference.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3060,7 +3060,8 @@ Utilities
30603060
handle_signals=True, \
30613061
reuse_address=None, \
30623062
reuse_port=None, \
3063-
handler_cancellation=False)
3063+
handler_cancellation=False, \
3064+
**kwargs)
30643065
30653066
A high-level function for running an application, serving it until
30663067
keyboard interrupt and performing a
@@ -3170,6 +3171,9 @@ Utilities
31703171
scalability is a concern.
31713172
:ref:`aiohttp-web-peer-disconnection`
31723173

3174+
:param kwargs: additional named parameters to pass into
3175+
:class:`AppRunner` constructor.
3176+
31733177
.. versionadded:: 3.0
31743178

31753179
Support *access_log_class* parameter.

tests/test_run_app.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -884,22 +884,29 @@ async def on_startup(app):
884884
exc_handler.assert_called_with(patched_loop, msg)
885885

886886

887-
def test_run_app_keepalive_timeout(patched_loop, mocker, monkeypatch):
888-
new_timeout = 1234
887+
@pytest.mark.parametrize(
888+
"param",
889+
(
890+
"keepalive_timeout",
891+
"max_line_size",
892+
"max_headers",
893+
"max_field_size",
894+
"lingering_time",
895+
"read_bufsize",
896+
"auto_decompress",
897+
),
898+
)
899+
def test_run_app_pass_apprunner_kwargs(param, patched_loop, monkeypatch):
900+
m = mock.Mock()
889901
base_runner_init_orig = BaseRunner.__init__
890902

891903
def base_runner_init_spy(self, *args, **kwargs):
892-
assert kwargs["keepalive_timeout"] == new_timeout
904+
assert kwargs[param] is m
893905
base_runner_init_orig(self, *args, **kwargs)
894906

895907
app = web.Application()
896908
monkeypatch.setattr(BaseRunner, "__init__", base_runner_init_spy)
897-
web.run_app(
898-
app,
899-
keepalive_timeout=new_timeout,
900-
print=stopper(patched_loop),
901-
loop=patched_loop,
902-
)
909+
web.run_app(app, print=stopper(patched_loop), loop=patched_loop, **{param: m})
903910

904911

905912
def test_run_app_context_vars(patched_loop):

0 commit comments

Comments
 (0)