encode

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package encode implements an encoder middleware for Kengine. 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptedEncodings

func AcceptedEncodings(r *http.Request, preferredOrder []string) []string

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.

Types

type Encode

type Encode struct {
	// Selection of compression algorithms to choose from. The best one
	// will be chosen based on the client's Accept-Encoding header.
	EncodingsRaw kengine.ModuleMap `json:"encodings,omitempty" kengine:"namespace=http.encoders"`

	// If the client has no strong preference, choose these encodings in order.
	Prefer []string `json:"prefer,omitempty"`

	// Only encode responses that are at least this many bytes long.
	MinLength int `json:"minimum_length,omitempty"`

	// Only encode responses that match against this ResponseMmatcher.
	// The default is a collection of text-based Content-Type headers.
	Matcher *kenginehttp.ResponseMatcher `json:"match,omitempty"`
	// contains filtered or unexported fields
}

Encode is a middleware which can encode responses.

func (Encode) KengineModule

func (Encode) KengineModule() kengine.ModuleInfo

KengineModule returns the Kengine module information.

func (*Encode) Match

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

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

func (*Encode) Provision

func (enc *Encode) Provision(ctx kengine.Context) error

Provision provisions enc.

func (*Encode) ServeHTTP

func (enc *Encode) ServeHTTP(w http.ResponseWriter, r *http.Request, next kenginehttp.Handler) error

func (*Encode) UnmarshalKenginefile

func (enc *Encode) UnmarshalKenginefile(d *kenginefile.Dispenser) error

UnmarshalKenginefile sets up the handler from Kenginefile tokens. Syntax:

encode [<matcher>] <formats...> {
    gzip           [<level>]
    zstd
    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 (*Encode) Validate

func (enc *Encode) Validate() error

Validate ensures that enc's configuration is valid.

type Encoder

type Encoder interface {
	io.WriteCloser
	Reset(io.Writer)
	Flush() error // encoder by default buffers data to maximize compressing rate
}

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

type Encoding

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

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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