Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Brotli ¶ added in v5.2.0
type Brotli struct { // Quality controls the compression-speed vs compression-density trade-offs. // The higher the quality, the slower the compression. Range is 0 to 11. Quality int // LGWin is the base 2 logarithm of the sliding window size. // Range is 10 to 24. 0 indicates automatic configuration based on Quality. LGWin int }
Brotli encoder for the br compression format
type Encoder ¶
type Encoder interface { NewWriter(wr io.Writer) io.WriteCloser Encoding() string }
Encoder is an interface that wraps the methods returning the information necessary for the compress middleware to work.
`NewWriter` returns any `io.WriteCloser`, allowing the middleware to support any compression algorithm.
`Encoding` returns the name of the compression algorithm. Using the returned value, the middleware:
- detects the client's preferred encoding with the `Accept-Encoding` request header
- replaces the response writer with the writer returned by `NewWriter`
- sets the `Content-Encoding` response header
type Gzip ¶
type Gzip struct {
Level int
}
Gzip encoder for the gzip format using Go's standard `compress/gzip` package.
Takes a compression level as parameter. Accepted values are defined by constants in the standard `compress/gzip` package.
type LZW ¶ added in v5.2.0
type LZW struct { // Order specifies the bit ordering in an LZW data stream. // It is optional, and the default value is lzw.LSB (Least Significant Bits) Order lzw.Order // LitWidth specifies the number of bits to use for literal codes // Must be in the range [2,8] and is typically 8. // Input bytes must be less than 1<<litWidth. LitWidth int }
LZW encoder for the compress format using Go's standard `compress/lzw` package.
Takes an Order specifying the bit ordering in an LZW data stream level, and number of bits to use for literal codes, litWidth, as parameters. Accepted values are defined by constants in the standard `compress/lzw` package.
func (*LZW) NewWriter ¶ added in v5.2.0
func (w *LZW) NewWriter(wr io.Writer) io.WriteCloser
NewWriter returns a new `compress/lzw.Writer` using an LZW bit ordering type, and an int for number of bits to use for literal codes - must be within range [2, 8] Default to a LitWidth of 8 if LitWidth was not set
type Middleware ¶
type Middleware struct { goyave.Component Encoders []Encoder }
Middleware compresses HTTP responses.
This middleware supports multiple algorithms thanks to the `Encoders` slice. The encoder will be chosen depending on the request's `Accept-Encoding` header, and the value returned by the `Encoder`'s `Encoding()` method. Quality values in the headers are taken into account.
In case of equal priority, the encoding that is the earliest in the slice is chosen. If the header's value is `*` and no encoding already matched, the first element of the slice is used.
If none of the accepted encodings are available in the `Encoders` slice, then the response will not be compressed and the middleware immediately passes.
If the middleware successfully replaces the response writer, the `Accept-Encoding` header is removed from the request to avoid potential clashes with potential other encoding middleware.
If not set at the first call of `Write()`, the middleware will automatically detect and set the `Content-Type` header using `http.DetectContentType()`.
The middleware ignores hijacked responses or requests containing the `Upgrade` header.
**Example:**
compressMiddleware := &compress.Middleware{ Encoders: []compress.Encoder{ &compress.Gzip{Level: gzip.BestCompression}, }, }
func (*Middleware) Handle ¶
func (m *Middleware) Handle(next goyave.Handler) goyave.Handler
Handle implementation of `goyave.Middleware`.
type Zlib ¶ added in v5.2.0
Zlib encoder for the deflate format using Go's standard `compress/zlib` package. Takes a compression level and "dict" ([]byte) as parameters. Accepted values are defined by constants in the standard `compress/zlib` package.