caddybrotli

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: MIT Imports: 6 Imported by: 0

README

Brotli for Caddy

This package implements a brotli encoder for Caddy.

Requires Caddy 2+.

Uses the pure go brotli implementation https://github.com/andybalholm/brotli

This implementation is NOT high performance, so it is not recommended to use this encoding as primary compression algorithm. Use gzip instead.

Installation

xcaddy build --with github.com/ueffel/caddy-brotli

Syntax

There will be the new encoding br available within the encode directive

encode [<matcher>] <formats...> {
    br [<level>]
}

level controls the compression level (ranges from 0 to 11), default is 4.

Example usages could look like this:

encode br
encode {
    br 4
}

or together with gzip

encode gzip br
encode {
    gzip 5
    br 4
}

Remarks

Update 2: From Caddy v2.4.0 onwards preferred order is implied by definition order.

Update: Since Caddy v2.4.0-beta.2 the preferred order of encodings can be set via prefer setting.

There is currently no way to set a prefered order of content-encodings via caddy's configuration. The content-encoding is determined by the clients preference. In most cases that means a response is encoded with the first accepted encoding in the Accept-Encoding header of the request that the caddy also supports.

Example:

Caddyfile

encode gzip br
  • Request:

    [...]
    Accept-Encoding: deflate, gzip, br
    [...]
    

    Response will be:

    [...]
    Content-Encoding: gzip
    [...]
    
  • Request: (different order of encodings)

    [...]
    Accept-Encoding: deflate, br, gzip
    [...]
    

    Response will be:

    [...]
    Content-Encoding: br
    [...]
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Brotli

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

Brotli can create brotli encoders.

func (Brotli) AcceptEncoding

func (Brotli) AcceptEncoding() string

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

func (Brotli) CaddyModule

func (Brotli) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (Brotli) NewEncoder

func (b Brotli) NewEncoder() encode.Encoder

NewEncoder returns a new brotli writer.

func (*Brotli) Provision

func (b *Brotli) Provision(ctx caddy.Context) error

Provision provisions b's configuration.

func (*Brotli) UnmarshalCaddyfile

func (b *Brotli) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the encoder from Caddyfile tokens.

func (Brotli) Validate

func (b Brotli) Validate() error

Validate validates b's configuration.

Jump to

Keyboard shortcuts

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