compression

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Unlicense Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CompressMinSizeDefault = 1024
)

Variables

View Source
var Default = New(Options{})

Get the default compression middleware. All options are defaulted.

Functions

func DefaultFilter

func DefaultFilter(request *http.Request) bool

Default filter function which applies compression to text/* and application/* content types.

func New

func New(options Options) xhttp.Middleware

Create a Middleware that compresses response automatically based on content encoding, type, and length.

Types

type Algorithm

type Algorithm struct {
	// Name of an encoding algorithm which must match an Accept-Encoding value
	// exactly.
	Name string
	// Return a WriteCloser that wraps the provided io.Writer with compression.
	GetWriter func(io.Writer) (io.WriteCloser, error)
}

Compression algorithm definition.

func Brotli

func Brotli() Algorithm

Brotli compression algorithm with default compression level.

func BrotliLevel

func BrotliLevel(level int) Algorithm

Brotli compression algorithm with custom compression level.

func Deflate

func Deflate() Algorithm

Deflate compression algorithm with default compression level.

func DeflateLevel

func DeflateLevel(level int) Algorithm

Deflate compression algorithm with custom compression level.

func Gzip

func Gzip() Algorithm

Gzip compression algorithm with default compression level.

func GzipLevel

func GzipLevel(level int) Algorithm

Gzip compression algorithm with custom compression level.

func Zstd

func Zstd() Algorithm

Zstd compression algorithm with default compression level.

func ZstdLevel

func ZstdLevel(level zstd.EncoderLevel) Algorithm

Zstd compression algorithm with custom compression level.

type Filter

type Filter func(request *http.Request) bool

type Options

type Options struct {
	// Filter requests that are eligible for compression. If nil, all text/* and
	// application/* types are compressed.
	Filter Filter
	// Minimum size in bytes to trigger compression. If zero,
	// CompressMinSizeDefault is used.
	MinSize int
	// Supported compression Algorithm slice in order of preference. If empty,
	// Brotli, Gzip, and Deflate are supported.
	Algorithms []Algorithm
}

Compression middleware options.

Jump to

Keyboard shortcuts

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