redirect#
- class litestar.response.redirect.ASGIRedirectResponse#
Bases:
ASGIResponse
A low-level ASGI redirect response class.
- __init__(path: str | bytes, media_type: str | None = None, status_code: RedirectStatusType | None = None, headers: dict[str, Any] | None = None, encoded_headers: Iterable[tuple[bytes, bytes]] | None = None, background: BackgroundTask | BackgroundTasks | None = None, body: bytes | str = b'', content_length: int | None = None, cookies: Iterable[Cookie] | None = None, encoding: str = 'utf-8', is_head_response: bool = False) None #
A low-level ASGI response class.
- Parameters:
background¶ – A background task or a list of background tasks to be executed after the response is sent.
body¶ – encoded content to send in the response body.
content_length¶ – The response content length.
cookies¶ – The response cookies.
encoded_headers¶ – The response headers.
encoding¶ – The response encoding.
headers¶ – The response headers.
is_head_response¶ – A boolean indicating if the response is a HEAD response.
media_type¶ – The response media type.
status_code¶ – The response status code.
- class litestar.response.redirect.Redirect#
-
A redirect response.
- __init__(path: str, *, background: BackgroundTask | BackgroundTasks | None = None, cookies: ResponseCookies | None = None, encoding: str = 'utf-8', headers: ResponseHeaders | None = None, media_type: str | MediaType | None = None, status_code: RedirectStatusType | None = None, type_encoders: TypeEncodersMap | None = None) None #
Initialize the response.
- Parameters:
path¶ – A path to redirect to.
background¶ – A background task or tasks to be run after the response is sent.
cookies¶ – A list of
Cookie
instances to be set under the responseSet-Cookie
header.encoding¶ – The encoding to be used for the response headers.
headers¶ – A string keyed dictionary of response headers. Header keys are insensitive.
media_type¶ – A value for the response
Content-Type
header.status_code¶ – An HTTP status code. The status code should be one of 301, 302, 303, 307 or 308, otherwise an exception will be raised.
type_encoders¶ – A mapping of types to callables that transform them into types supported for serialization.
- Raises:
ImproperlyConfiguredException – Either if status code is not a redirect status code or media type is not supported.
- to_asgi_response(app: Litestar | None, request: Request, *, background: BackgroundTask | BackgroundTasks | None = None, cookies: Iterable[Cookie] | None = None, encoded_headers: Iterable[tuple[bytes, bytes]] | None = None, headers: dict[str, str] | None = None, is_head_response: bool = False, media_type: MediaType | str | None = None, status_code: int | None = None, type_encoders: TypeEncodersMap | None = None) ASGIResponse #
Create an ASGIResponse from a Response instance.
- Parameters:
background¶ – Background task(s) to be executed after the response is sent.
cookies¶ – A list of cookies to be set on the response.
encoded_headers¶ – A list of already encoded headers.
headers¶ – Additional headers to be merged with the response headers. Response headers take precedence.
is_head_response¶ – Whether the response is a HEAD response.
media_type¶ – Media type for the response. If
media_type
is already set on the response, this is ignored.status_code¶ – Status code for the response. If
status_code
is already set on the response, this istype_encoders¶ – A dictionary of type encoders to use for encoding the response content.
- Returns:
An ASGIResponse instance.