pkg.go.dev

Package encode implements an encoder middleware for Caddy. The initial enhancements related to Accept-Encoding, minimum content length, and buffer/writer pools were adapted from https://github.com/xi2/httpgzip then modified heavily to accommodate modular encoders and fix bugs. Code borrowed from that repository is Copyright (c) 2015 The Httpgzip Authors.

This section is empty.

This section is empty.

AcceptedEncodings returns the list of encodings that the client supports, in descending order of preference. The client preference via q-factor and the server preference via Prefer setting are taken into account. If the Sec-WebSocket-Key header is present then non-identity encodings are not considered. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html.

type Encode struct {


	EncodingsRaw caddy.ModuleMap `json:"encodings,omitempty" caddy:"namespace=http.encoders"`

	Prefer []string `json:"prefer,omitempty"`

	MinLength int `json:"minimum_length,omitempty"`


	Matcher *caddyhttp.ResponseMatcher `json:"match,omitempty"`
}

Encode is a middleware which can encode responses.

CaddyModule returns the Caddy module information.

func (enc *Encode) Match(rw *responseWriter) bool

Match determines, if encoding should be done based on the ResponseMatcher.

Provision provisions enc.

UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:

encode [<matcher>] <formats...> {
    gzip           [<level>]
    zstd           [<level>] {
        level           <level>
        disable_checksum
    }
    minimum_length <length>
    # response matcher block
    match {
        status <code...>
        header <field> [<value>]
    }
    # or response matcher single line syntax
    match [header <field> [<value>]] | [status <code...>]
}

Specifying the formats on the first line will use those formats' defaults.

func (enc *Encode) Validate() error

Validate ensures that enc's configuration is valid.

Encoder is a type which can encode a stream of data.

type Encoding interface {
	AcceptEncoding() string
	NewEncoder() Encoder
}

Encoding is a type which can create encoders of its kind and return the name used in the Accept-Encoding header.

type Precompressed interface {
	AcceptEncoding() string
	Suffix() string
}

Precompressed is a type which returns filename suffix of precompressed file and Accept-Encoding header to use when serving this file.

Read the original on pkg.go.dev ↗