Go API Documentation

github.com/caddyserver/caddy/v2/modules/caddyhttp/encode/gzip

No package summary is available.

Package

Files: 2. Third party imports: 1. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Vars

var (
	_	encode.Encoding		= (*Gzip)(nil)
	_	caddy.Provisioner	= (*Gzip)(nil)
	_	caddy.Validator		= (*Gzip)(nil)
	_	caddyfile.Unmarshaler	= (*Gzip)(nil)
)

Informed from http://blog.klauspost.com/gzip-performance-for-go-webservers/

var defaultGzipLevel = 5

Types

Gzip

Gzip can create gzip encoders.

type Gzip struct {
	Level int `json:"level,omitempty"`
}

GzipPrecompressed

GzipPrecompressed provides the file extension for files precompressed with gzip encoding.

type GzipPrecompressed struct {
	Gzip
}

Functions

func (*Gzip) Provision

Provision provisions g's configuration.

func (g *Gzip) Provision(ctx caddy.Context) error {
	if g.Level == 0 {
		g.Level = defaultGzipLevel
	}
	return nil
}

Cognitive complexity: 2, Cyclomatic complexity: 2

func (*Gzip) UnmarshalCaddyfile

UnmarshalCaddyfile sets up the handler from Caddyfile tokens.

func (g *Gzip) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
	d.Next()	// consume option name
	if !d.NextArg() {
		return nil
	}
	levelStr := d.Val()
	level, err := strconv.Atoi(levelStr)
	if err != nil {
		return err
	}
	g.Level = level
	return nil
}

Cognitive complexity: 4, Cyclomatic complexity: 3

Uses: strconv.Atoi.

func (Gzip) AcceptEncoding

AcceptEncoding returns the name of the encoding as used in the Accept-Encoding request headers.

func (Gzip) AcceptEncoding() string	{ return "gzip" }

Cognitive complexity: 0, Cyclomatic complexity: 1

func (Gzip) CaddyModule

CaddyModule returns the Caddy module information.

func (Gzip) CaddyModule() caddy.ModuleInfo {
	return caddy.ModuleInfo{
		ID:	"http.encoders.gzip",
		New:	func() caddy.Module { return new(Gzip) },
	}
}

Cognitive complexity: 2, Cyclomatic complexity: 1

func (Gzip) NewEncoder

NewEncoder returns a new gzip writer.

func (g Gzip) NewEncoder() encode.Encoder {
	writer, _ := gzip.NewWriterLevel(nil, g.Level)
	return writer
}

Cognitive complexity: 0, Cyclomatic complexity: 1

Uses: gzip.NewWriterLevel.

func (Gzip) Validate

Validate validates g's configuration.

func (g Gzip) Validate() error {
	if g.Level < gzip.StatelessCompression {
		return fmt.Errorf("quality too low; must be >= %d", gzip.StatelessCompression)
	}
	if g.Level > gzip.BestCompression {
		return fmt.Errorf("quality too high; must be <= %d", gzip.BestCompression)
	}
	return nil
}

Cognitive complexity: 4, Cyclomatic complexity: 3

Uses: fmt.Errorf, gzip.BestCompression, gzip.StatelessCompression.

func (GzipPrecompressed) Suffix

Suffix returns the filename suffix of precompressed files.

func (GzipPrecompressed) Suffix() string	{ return ".gz" }

Cognitive complexity: 0, Cyclomatic complexity: 1

Private functions

func init

init ()