Skip to content

Commit b39fd63

Browse files
authored
[PR #11633/b1bd65d backport][3.13] Make AppRunner's configuration options available in run_app() (#11652)
(cherry picked from commit b1bd65d)
1 parent 040dac3 commit b39fd63

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

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
@@ -309,35 +309,20 @@ async def _run_app(
309309
port: Optional[int] = None,
310310
path: Union[PathLike, TypingIterable[PathLike], None] = None,
311311
sock: Optional[Union[socket.socket, TypingIterable[socket.socket]]] = None,
312-
shutdown_timeout: float = 60.0,
313-
keepalive_timeout: float = 75.0,
314312
ssl_context: Optional[SSLContext] = None,
315313
print: Optional[Callable[..., None]] = print,
316314
backlog: int = 128,
317-
access_log_class: Type[AbstractAccessLogger] = AccessLogger,
318-
access_log_format: str = AccessLogger.LOG_FORMAT,
319-
access_log: Optional[logging.Logger] = access_logger,
320-
handle_signals: bool = True,
321315
reuse_address: Optional[bool] = None,
322316
reuse_port: Optional[bool] = None,
323-
handler_cancellation: bool = False,
317+
**kwargs: Any, # TODO(PY311): Use Unpack
324318
) -> None:
325319
# An internal function to actually do all dirty job for application running
326320
if asyncio.iscoroutine(app):
327321
app = await app
328322

329323
app = cast(Application, app)
330324

331-
runner = AppRunner(
332-
app,
333-
handle_signals=handle_signals,
334-
access_log_class=access_log_class,
335-
access_log_format=access_log_format,
336-
access_log=access_log,
337-
keepalive_timeout=keepalive_timeout,
338-
shutdown_timeout=shutdown_timeout,
339-
handler_cancellation=handler_cancellation,
340-
)
325+
runner = AppRunner(app, **kwargs)
341326

342327
await runner.setup()
343328

@@ -484,6 +469,7 @@ def run_app(
484469
reuse_port: Optional[bool] = None,
485470
handler_cancellation: bool = False,
486471
loop: Optional[asyncio.AbstractEventLoop] = None,
472+
**kwargs: Any,
487473
) -> None:
488474
"""Run an app locally"""
489475
if loop is None:
@@ -515,6 +501,7 @@ def run_app(
515501
reuse_address=reuse_address,
516502
reuse_port=reuse_port,
517503
handler_cancellation=handler_cancellation,
504+
**kwargs,
518505
)
519506
)
520507

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
@@ -893,22 +893,29 @@ async def on_startup(app):
893893
exc_handler.assert_called_with(patched_loop, msg)
894894

895895

896-
def test_run_app_keepalive_timeout(patched_loop, mocker, monkeypatch):
897-
new_timeout = 1234
896+
@pytest.mark.parametrize(
897+
"param",
898+
(
899+
"keepalive_timeout",
900+
"max_line_size",
901+
"max_headers",
902+
"max_field_size",
903+
"lingering_time",
904+
"read_bufsize",
905+
"auto_decompress",
906+
),
907+
)
908+
def test_run_app_pass_apprunner_kwargs(param, patched_loop, monkeypatch):
909+
m = mock.Mock()
898910
base_runner_init_orig = BaseRunner.__init__
899911

900912
def base_runner_init_spy(self, *args, **kwargs):
901-
assert kwargs["keepalive_timeout"] == new_timeout
913+
assert kwargs[param] is m
902914
base_runner_init_orig(self, *args, **kwargs)
903915

904916
app = web.Application()
905917
monkeypatch.setattr(BaseRunner, "__init__", base_runner_init_spy)
906-
web.run_app(
907-
app,
908-
keepalive_timeout=new_timeout,
909-
print=stopper(patched_loop),
910-
loop=patched_loop,
911-
)
918+
web.run_app(app, print=stopper(patched_loop), loop=patched_loop, **{param: m})
912919

913920

914921
def test_run_app_context_vars(patched_loop):

0 commit comments

Comments
 (0)