From 3de86c15cf403cbaa5e57549c4b95837c19f2659 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 17 May 2023 16:54:42 +0000 Subject: [PATCH] [PR #7283/0e7c272f backport][3.9] Add note about updating headers in on_response_prepare (#7294) **This is a backport of PR #7283 as merged into master (0e7c272f8b7e7c610819ee362aeae234c308449c).** Fixes #6443. It seems like it'll be easier just to document this. Only solution that looks like it'd work is to update the Content-Length header every time the body is changed, but that could incur a performance penalty for little reason. Co-authored-by: Sam Bull --- CHANGES/7283.doc | 1 + docs/web_reference.rst | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 CHANGES/7283.doc diff --git a/CHANGES/7283.doc b/CHANGES/7283.doc new file mode 100644 index 00000000000..71a1a6722fc --- /dev/null +++ b/CHANGES/7283.doc @@ -0,0 +1 @@ +Added a note about possibly needing to update headers when using ``on_response_prepare`` -- by :user:`Dreamsorcerer` diff --git a/docs/web_reference.rst b/docs/web_reference.rst index 8b32658e1aa..b3f8518dd1b 100644 --- a/docs/web_reference.rst +++ b/docs/web_reference.rst @@ -1427,6 +1427,13 @@ duplicated like one using :meth:`~aiohttp.web.Application.copy`. async def on_prepare(request, response): pass + .. note:: + + The headers are written immediately after these callbacks are run. + Therefore, if you modify the content of the response, you may need to + adjust the `Content-Length` header or similar to match. Aiohttp will + not make any updates to the headers from this point. + .. attribute:: on_startup A :class:`~aiosignal.Signal` that is fired on application start-up.