Skip to content

Commit

Permalink
Add note about updating headers in on_response_prepare (#7283)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dreamsorcerer authored May 17, 2023
1 parent a29e9de commit 0e7c272
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/7283.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a note about possibly needing to update headers when using ``on_response_prepare`` -- by :user:`Dreamsorcerer`
7 changes: 7 additions & 0 deletions docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,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.
Expand Down

0 comments on commit 0e7c272

Please sign in to comment.