Documentation
¶
Index ¶
Constants ¶
const DefaultMinSize = 1024
DefaultMinSize is the default minimum body size to compress.
Variables ¶
var ErrInvalidConfig = errors.New("invalid config")
Functions ¶
func Middleware ¶
func Middleware(opts ...Option) (fox.MiddlewareFunc, error)
Middleware returns a fox.MiddlewareFunc that compresses responses with the encoding preferred by the client, among the configured encoders.
Types ¶
type Encoder ¶
type Encoder interface {
// Encoding returns the encoding name, such as "gzip".
Encoding() string
// NewWriter returns a new [Writer] that writes to w.
// Internally, writers are pooled.
NewWriter(w io.Writer) Writer
}
Encoder creates the Writer for a content encoding.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures the middleware.
func WithEncoders ¶
WithEncoders sets the encoders in order of preference. A preference expressed by the client takes precedence over this order. The default is zstd, br then gzip.
func WithExcludedContentTypes ¶
WithExcludedContentTypes never compresses the given media types, in addition to the default ones (already compressed formats and gRPC). A "type/*" entry matches any subtype. It cannot be combined with WithIncludedContentTypes.
func WithIncludedContentTypes ¶
WithIncludedContentTypes compresses only the given media types. A "type/*" entry matches any subtype. It cannot be combined with WithExcludedContentTypes.
func WithMinSize ¶
WithMinSize sets the minimum body size to compress. Smaller bodies are sent as is. The default is DefaultMinSize.
type Writer ¶
type Writer interface {
io.WriteCloser
// Flush writes any pending compressed data to the underlying writer.
Flush() error
// Reset discards the writer state and makes it write to w. The middleware calls Reset(nil) before
// returning a writer to its pool.
Reset(w io.Writer)
}
Writer is a resettable compressor.