Documentation
¶
Overview ¶
Package compress provides response-compression middleware for httpsrv (New(config) -> Handler).
Register it with Use; it compresses responses with gzip or brotli, chosen from the request's Accept-Encoding (brotli preferred, then gzip):
import "github.com/hooto/httpsrv/v2"
"github.com/hooto/httpsrv/v2/middleware/compress"
app.Use(compress.New())
// or: app.Use(compress.New(compress.Config{Level: compress.LevelBestSpeed}))
It wraps the response writer, sets Content-Encoding (and Vary), and removes any Content-Length the handler may have set. All response bodies are compressed; there is no content-type or minimum-size filter.
Index ¶
Constants ¶
View Source
const ( LevelDefault = iota // 0: gzip DefaultCompression, brotli quality 5 LevelBestSpeed // 1: gzip BestSpeed, brotli BestSpeed LevelBestCompression // 2: gzip BestCompression, brotli BestCompression )
Compression levels. They are an enum (not raw gzip/brotli levels); New maps each to the appropriate encoder level.
Variables ¶
View Source
var ConfigDefault = Config{ Level: LevelDefault, }
ConfigDefault is the default configuration (LevelDefault, no Next).
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Next optionally skips this middleware when it returns true.
Next func(c httpsrv.Ctx) bool
// Level is the compression level: LevelDefault (default), LevelBestSpeed,
// or LevelBestCompression. Defaults to LevelDefault.
Level int
}
Config configures the compression middleware.
Click to show internal directories.
Click to hide internal directories.