response_containers#
- class starlite.datastructures.response_containers.ResponseContainer#
Bases:
ABC
,GenericModel
,Generic
[R
]Generic response container.
- background: Optional[Union[BackgroundTask, BackgroundTasks]]#
A
BackgroundTask
instance or.BackgroundTasks
to execute after the response is finished. Defaults to None.
- headers: Dict[str, Any]#
A string/string dictionary of response headers.
Header keys are insensitive. Defaults to None.
- cookies: List[Cookie]#
A list of Cookie instances to be set under the response ‘Set-Cookie’ header.
Defaults to None.
- media_type: Optional[Union[MediaType, str]]#
If defined, overrides the media type configured in the route decorator.
- class starlite.datastructures.response_containers.File#
Bases:
ResponseContainer[FileResponse]
Container type for returning File responses.
- path: FilePath#
Path to the file to send.
- stat_result: Optional[stat_result]#
An optional result of calling ‘os.stat’.
If not provided, this will be done by the response constructor.
- content_disposition_type: Literal['attachment', 'inline']#
The type of the ‘Content-Disposition’.
Either ‘inline’ or ‘attachment’.
- etag: Optional[ETag]#
An optional
ETag
instance.If not provided, an etag will be automatically generated.
- file_system: Any#
The file_system spec to use loading the file.
Notes
- A file_system is a class that adheres to the
- You can use any of the file systems exported from the
[fsspec](https://filesystem-spec.readthedocs.io/en/latest/) library for this purpose.
- file_info: Optional[FileInfo]#
The output of calling file_system.info(..), equivalent to providing a
stat_result
.
- classmethod validate_status_code(value: Optional[stat_result], values: Dict[str, Any]) stat_result #
Set the stat_result value for the given filepath.
- Parameters:
value – An optional result
stat
result.values – The dict of values.
- Returns:
A stat_result
- classmethod validate_file_system(value: FileSystemProtocol) FileSystemProtocol #
Ensure the value is a file system spec.
- Parameters:
value – A file system spec.
- Returns:
A file system spec.
- class starlite.datastructures.response_containers.Redirect#
Bases:
ResponseContainer[RedirectResponse]
Container type for returning Redirect responses.
- class starlite.datastructures.response_containers.Stream#
Bases:
ResponseContainer[StreamingResponse]
Container type for returning Stream responses.
- iterator: Union[Iterable[Union[str, bytes]], Iterator[Union[str, bytes]], AsyncIterable[Union[str, bytes]], AsyncIterator[Union[str, bytes]], Callable[[], Union[Iterable[Union[str, bytes]], Iterator[Union[str, bytes]], AsyncIterable[Union[str, bytes]], AsyncIterator[Union[str, bytes]]]]]#
Iterator, Iterable,Generator or async Iterator, Iterable or Generator returning chunks to stream.
- classmethod validate_iterator(value: Union[Iterable[Union[str, bytes]], Iterator[Union[str, bytes]], AsyncIterable[Union[str, bytes]], AsyncIterator[Union[str, bytes]], Callable[[], Union[Iterable[Union[str, bytes]], Iterator[Union[str, bytes]], AsyncIterable[Union[str, bytes]], AsyncIterator[Union[str, bytes]]]]]) Union[Iterable[Union[str, bytes]], Iterator[Union[str, bytes]], AsyncIterable[Union[str, bytes]], AsyncIterator[Union[str, bytes]]] #
Set the iterator value by ensuring that the return value is iterable.
- Parameters:
value – An iterable or callable returning an iterable.
- Returns:
A sync or async iterable.
- class starlite.datastructures.response_containers.Template#
Bases:
ResponseContainer[TemplateResponse]
Container type for returning Template responses.
- context: Dict[str, Any]#
A dictionary of key/value pairs to be passed to the temple engine’s render method.
Defaults to None.
- to_response(headers: Dict[str, Any], media_type: Union[MediaType, str], status_code: int, app: Starlite, request: Request) TemplateResponse #
Create a TemplateResponse instance.
- Parameters:
- Raises:
ImproperlyConfiguredException <starlite.exceptions.ImproperlyConfiguredException> – if app.template_engine is not configured.
- Returns:
A TemplateResponse instance