caddycbrotli

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: MIT Imports: 7 Imported by: 2

README

Caddy Brotli Module

This module for the Caddy web server provides support for the Brotli compression format.

It uses the reference implementation of Brotli (written in C), through the Go module provided by Google.

Tests Go Reference

Install

  1. Install cbrotli. On Mac run brew install brotli. On Debian and Ubuntu, run apt install libbrotli-dev.

  2. Then create your Caddy build:

    CGO_ENABLED=1 \
    xcaddy build \
        --with github.com/dunglas/caddy-cbrotli
    

    On Mac, be sure to adapt the paths in CGO_LDFLAGS and CGO_CFLAGS according to your Brotli installation:

    CGO_LDFLAGS="-L/opt/homebrew/lib/" \
    CGO_CFLAGS="-I/opt/homebrew/include/" \
    CGO_ENABLED=1 \
    xcaddy build \
        --with github.com/dunglas/caddy-cbrotli
    

Usage

Add the br value to the encode directive in your Caddyfile.

Example:

localhost

encode zstd br gzip

file_server

Alternatively, you can configure the quality (from 0 to 11, defaults to 6) and the base 2 logarithm of the sliding window size (from 10 to 24, defaults to auto):

Example:

localhost

encode {
    br 8 15
}

file_server

Cgo

This module depends on cgo. If you are looking for a non-cgo (but more CPU-intensive) alternative, see the github.com/ueffel/caddy-brotli module.

Credits

Created by Kévin Dunglas and sponsored by Les-Tilleuls.coop.

Documentation

Overview

Package caddycbrotli provides provides support for the Brotli compression format using a fast and efficient implementation written in C.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Br

type Br struct {
	// Quality controls the compression-speed vs compression-density trade-offs.
	// The higher the quality, the slower the compression. Range is 0 to 11. Defaults to 6.
	Quality *int `json:"quality,omitempty"`
	// 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 `json:"lgwin,omitempty"`
}

Br can create Brotli encoders.

func (Br) AcceptEncoding

func (Br) AcceptEncoding() string

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

func (Br) CaddyModule

func (Br) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (Br) NewEncoder

func (b Br) NewEncoder() encode.Encoder

NewEncoder returns a new Brotli writer.

func (*Br) UnmarshalCaddyfile

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

UnmarshalCaddyfile sets up the handler from Caddyfile tokens.

func (Br) Validate

func (b Br) 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