Help us shape the future of Go! Take the 2026 Go Developer Survey

compress

package
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 8 Imported by: 0

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

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

func AcceptsEncodingStr(header, enc string) bool

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

func GzipBytes(src []byte, level int) ([]byte, error)

GzipBytes compresses src with the configured level and returns the result. Used during cache population to pre-compress file contents.

func IsCompressible

func IsCompressible(contentType string) bool

IsCompressible reports whether the given content type should be compressed.

func Middleware

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.

func ZstdBytes added in v1.6.0

func ZstdBytes(src []byte) ([]byte, error)

ZstdBytes compresses src with the default zstd level and returns the result. Used during cache population to pre-compress file contents.

func ZstdBytesLevel added in v1.6.0

func ZstdBytesLevel(src []byte, level zstd.EncoderLevel) ([]byte, error)

ZstdBytesLevel compresses src with the specified zstd level and returns the result. The level can be zstd.SpeedFastest, zstd.SpeedDefault, zstd.SpeedBetter, or zstd.SpeedBest.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL