Documentation
¶
Overview ¶
Package compress provides HTTP response compression middleware and utilities. It supports brotli (pre-compressed only), gzip (pre-compressed + on-the-fly), and transparent passthrough for already-compressed content types.
Index ¶
- func AcceptsEncoding(ctx *fasthttp.RequestCtx, enc string) bool
- func AcceptsEncodingStr(header, enc string) bool
- func GzipBytes(src []byte, level int) ([]byte, error)
- func IsCompressible(contentType string) bool
- func Middleware(cfg *config.CompressionConfig, next fasthttp.RequestHandler) fasthttp.RequestHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AcceptsEncoding ¶
func AcceptsEncoding(ctx *fasthttp.RequestCtx, enc string) bool
AcceptsEncoding reports whether the Accept-Encoding header includes enc. It parses the comma-separated list without allocating. Returns false if the encoding is explicitly rejected with q=0 (RFC 7231 §5.3.4).
func AcceptsEncodingStr ¶ added in v1.3.0
AcceptsEncodingStr reports whether the given Accept-Encoding header value includes enc. It parses the comma-separated list without allocating. Returns false if the encoding is explicitly rejected with q=0 (RFC 7231 §5.3.4).
func GzipBytes ¶
GzipBytes compresses src with the configured level and returns the result. Used during cache population to pre-compress file contents.
func IsCompressible ¶
IsCompressible reports whether the given content type should be compressed.
func Middleware ¶
func Middleware(cfg *config.CompressionConfig, next fasthttp.RequestHandler) fasthttp.RequestHandler
Middleware returns a fasthttp.RequestHandler that adds on-the-fly gzip compression for compressible content types when the client signals support. Pre-compressed serving (br/gz sidecar files) is handled in the file handler; this middleware only handles the on-the-fly gzip fallback for uncached or large files that bypass the cache.
With fasthttp, the response body is fully buffered, so we apply compression as a post-processing step after the inner handler writes the response.
Types ¶
This section is empty.