caddybrotli

package module
v0.0.0-...-04e4168 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Urchived in favor of https://github.com/ottenhoff/caddy-brrr

caddy-brotli

A Caddy v2 encoder module that adds brotli (br) response compression.

It registers the http.encoders.br module, so it is a drop-in alternative to ueffel/caddy-brotli. Compared to ueffel/caddy-brotli:

Build

Use xcaddy:

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

Because http.encoders.br can only be registered once, do not combine this with ueffel/caddy-brotli in the same build.

Usage

Brotli is added as a br encoding inside Caddy's encode directive.

# Defaults (level 4, go-brrr's default window).
encode br

# Alongside gzip; clients negotiate via Accept-Encoding.
encode gzip br

# Explicit compression level (0..11).
encode {
    br 6
}

# Explicit level and window size (lgwin, 10..24).
encode {
    br 6 22
}
Options
Option Range Default Description
level 0..11 4 Compression level. Higher compresses more but is slower. 0 is the fastest.
lgwin 10..24 22 Base-2 logarithm of the sliding window size. Larger windows compress more.
JSON config
{
  "handler": "encode",
  "encodings": { "br": { "level": 6, "lgwin": 22 } },
  "prefer": ["br"]
}

Benchmarks

Measured on an AWS c7g.large spot instance: Graviton3 (arm64). See the bench branch for the setup. Comparing zstd level default and brotli level 3 of this plugin and ueffel/caddy-brotli.

File Raw zstd ratio zstd req/s br ratio this plugin req/s ueffel req/s
mdn.html 195 KB 0.147 1698 0.138 1638 875
amazon.html 811 KB 0.201 373 0.195 369 189
nytimes.html 1.0 MB 0.144 393 0.130 395 191
wikipedia.html 1.0 MB 0.197 283 0.190 265 139

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Brotli

type Brotli struct {
	// Level is the compression level, 0..11. A nil pointer selects the default
	Level *int `json:"level,omitempty"`

	// LGWin is the base-2 logarithm of the sliding window size, 10..24. Default is 22
	LGWin int `json:"lgwin,omitempty"`
}

Brotli creates streaming brotli encoders backed by go-brrr.

func (Brotli) AcceptEncoding

func (Brotli) AcceptEncoding() string

func (Brotli) CaddyModule

func (Brotli) CaddyModule() caddy.ModuleInfo

func (Brotli) NewEncoder

func (b Brotli) NewEncoder() encode.Encoder

func (*Brotli) Provision

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

func (*Brotli) UnmarshalCaddyfile

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

UnmarshalCaddyfile parses `br [<level> [<lgwin>]]`.

Jump to

Keyboard shortcuts

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