streaming

class litestar.response.streaming.ASGIStreamingResponse[原始碼]

基底類別:ASGIResponse

A streaming response.

__init__(*, iterator: StreamType, background: BackgroundTask | BackgroundTasks | None = None, content_length: int | None = None, cookies: Iterable[Cookie] | None = None, encoding: str = 'utf-8', headers: dict[str, Any] | None = None, is_head_response: bool = False, media_type: MediaType | str | None = None, status_code: int | None = None) None[原始碼]

A low-level ASGI streaming response.

參數:
  • background -- A background task or a list of background tasks to be executed after the response is sent.

  • content_length -- The response content length.

  • cookies -- The response cookies.

  • encoding -- The response encoding.

  • headers -- The response headers.

  • is_head_response -- A boolean indicating if the response is a HEAD response.

  • iterator -- An async iterator or iterable.

  • media_type -- The response media type.

  • status_code -- The response status code.

async send_body(send: Send, receive: Receive) None[原始碼]

Emit a stream of events correlating with the response body.

參數:
  • send -- ASGI 發送函式。

  • receive -- ASGI 接收函式。

回傳:

None

class litestar.response.streaming.Stream[原始碼]

基底類別:Response[Iterable[str | bytes] | Iterator[str | bytes] | AsyncIterable[str | bytes] | AsyncIterator[str | bytes]]

An HTTP response that streams the response data as a series of ASGI http.response.body events.

__init__(content: StreamType[str | bytes] | Callable[[], StreamType[str | bytes]], *, background: BackgroundTask | BackgroundTasks | None = None, cookies: ResponseCookies | None = None, encoding: str = 'utf-8', headers: ResponseHeaders | None = None, media_type: MediaType | OpenAPIMediaType | str | None = None, status_code: int | None = None) None[原始碼]

Initialize the response.

參數:
  • content -- A sync or async iterator or iterable.

  • background -- A BackgroundTask instance or BackgroundTasks to execute after the response is finished. Defaults to None.

  • cookies -- A list of Cookie instances to be set under the response Set-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.

to_asgi_response(request: Request, *, background: BackgroundTask | BackgroundTasks | None = None, cookies: Iterable[Cookie] | 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 ASGIStreamingResponse from a StremaingResponse instance.

參數:
  • background -- Background task(s) to be executed after the response is sent.

  • cookies -- A list of cookies to be set on the response.

  • 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.

  • request -- The Request instance.

  • status_code -- Status code for the response. If status_code is already set on the response, this is

  • type_encoders -- A dictionary of type encoders to use for encoding the response content.

回傳:

An ASGIStreamingResponse instance.