Skip to content

Commit

Permalink
Documentation for Response.asgi_send(), closes #1266
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Mar 20, 2021
1 parent 8e18c79 commit c4f1ec7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/internals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ Each of these responses will use the correct corresponding content-type - ``text

Each of the helper methods take optional ``status=`` and ``headers=`` arguments, documented above.

.. _internals_response_asgi_send:

Returning a response with .asgi_send(send)
------------------------------------------


In most cases you will return ``Response`` objects from your own view functions. You can also use a ``Response`` instance to respond at a lower level via ASGI, for example if you are writing code that uses the :ref:`plugin_asgi_wrapper` hook.

Create a ``Response`` object and then use ``await response.asgi_send(send)``, passing the ASGI ``send`` function. For example:

.. code-block:: python
async def require_authorization(scope, recieve, send):
response = Response.text(
"401 Authorization Required",
headers={
"www-authenticate": 'Basic realm="Datasette", charset="UTF-8"'
},
status=401,
)
await response.asgi_send(send)
.. _internals_response_set_cookie:

Setting cookies with response.set_cookie()
Expand Down

0 comments on commit c4f1ec7

Please sign in to comment.