compression

class litestar.middleware.compression.CompressionFacade

基类:Protocol

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

encoding: ClassVar[str]

The encoding of the compression.

__init__(buffer: BytesIO, compression_encoding: CompressionEncoding | str, config: CompressionConfig) None

Initialize CompressionFacade.

参数:
  • buffer -- A bytes IO buffer to write the compressed data into.

  • compression_encoding -- The compression encoding used.

  • config -- The app compression config.

write(body: bytes) None

Write compressed bytes.

参数:

body -- Message body to process

返回:

None

close() None

Close the compression stream.

返回:

None

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

Initialize 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] | str, scope: Scope) Send

Wrap send to handle brotli compression.

参数:
  • send -- The ASGI send function.

  • compression_encoding -- The compression encoding used.

  • scope -- The ASGI connection scope

返回:

An ASGI send function.