compression

class litestar.middleware.compression.CompressionFacade[原始碼]

基底類別:Protocol

A unified facade offering a uniform interface for different compression libraries.

__init__(buffer: BytesIO, compression_encoding: CompressionEncoding | str, config: CompressionConfig) None[原始碼]

初始化 CompressionFacade

參數:
  • buffer -- A bytes IO buffer to write the compressed data into.

  • compression_encoding -- The compression encoding used.

  • config -- The app compression config.

close() None[原始碼]

Close the compression stream.

回傳:

None

write(body: bytes | bytearray, final: bool = False) None[原始碼]

Write compressed bytes to the buffer.

參數:
  • body -- The message body to process. Can be bytes or bytearray.

  • final -- Indicates whether this is the last chunk of data. If True, the compressor may flush any remaining internal buffers.

回傳:

None

encoding: ClassVar[str]

The encoding of the compression.

class litestar.middleware.compression.CompressionMiddleware[原始碼]

基底類別:AbstractMiddleware

Compression Middleware Wrapper.

This is a wrapper allowing for generic compression configuration / handler middleware

__init__(app: ASGIApp, config: CompressionConfig) None[原始碼]

初始化 CompressionMiddleware

參數:
  • app -- The next ASGI app to call.

  • config -- An instance of CompressionConfig.

create_compression_send_wrapper(send: Send, compression_encoding: Literal[CompressionEncoding.BROTLI, CompressionEncoding.GZIP, CompressionEncoding.ZSTD] | str, scope: Scope) Send[原始碼]

Wrap send to handle brotli compression.

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

  • compression_encoding -- The compression encoding used.

  • scope -- The ASGI connection scope

回傳:

An ASGI send function.