Skip to content

Commit

Permalink
fix: asgi redirect response in documentation (#2710)
Browse files Browse the repository at this point in the history
* Update creating-middleware.rst

Co-authored-by: Janek Nouvertné <[email protected]>

---------

Co-authored-by: Janek Nouvertné <[email protected]>
  • Loading branch information
hunterjsb and provinzkraut authored Nov 19, 2023
1 parent 906e91f commit 94e7ff7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/usage/middleware/creating-middleware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ explore another example - redirecting the request to a different url from a midd
from litestar.types import ASGIApp, Receive, Scope, Send
from litestar.response import Redirect
from litestar.response.redirect import ASGIRedirectResponse
from litestar import Request
from litestar.middleware.base import MiddlewareProtocol
Expand All @@ -110,13 +110,13 @@ explore another example - redirecting the request to a different url from a midd
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
if Request(scope).session is None:
response = Redirect(path="/login")
response = ASGIRedirectResponse(path="/login")
await response(scope, receive, send)
else:
await self.app(scope, receive, send)
As you can see in the above, given some condition (request.session being None) we create a
:class:`Redirect <litestar.response.Redirect>` and then await it. Otherwise, we await ``self.app``
:class:`ASGIRedirectResponse <litestar.response.ASGIRedirectResponse>` and then await it. Otherwise, we await ``self.app``


Modifying ASGI Requests and Responses using the MiddlewareProtocol
Expand Down

0 comments on commit 94e7ff7

Please sign in to comment.