Documentation
a project

encode

Encodes responses using the configured encoding(s). A typical use for encoding is compression.

Syntax

encode [<matcher>] <formats...> {
	# encoding formats
	gzip [<level>]
	zstd
	
	minimum_length <length>

	# response matcher single line syntax
	match [header <field> [<value>]] | [status <code...>]
	# or response matcher block for multiple conditions
	match {
		status <code...>
		header <field> [<value>]
	}
}
  • <formats...> is the list of encoding formats to enable. If multiple encodings are enabled, the encoding is chosen based the request's Accept-Encoding header; if the client has no strong preference (q-factor), then the first supported encoding is used.

  • gzip enables Gzip compression, optionally at the specified level.

  • zstd enables Zstandard compression.

  • minimum_length the minimum number of bytes a response should have to be encoded (default: 512).

  • match is a response matcher. Only matching responses are encoded. The default looks like this:

    match {
        header Content-Type text/*
        header Content-Type application/json*
        header Content-Type application/javascript*
        header Content-Type application/xhtml+xml*
        header Content-Type application/atom+xml*
        header Content-Type application/rss+xml*
        header Content-Type image/svg+xml*
    }
    

Response matcher

Response matchers can be used to filter (or classify) responses by specific criteria.

status

status <code...>

By HTTP status code.

  • <code...> is a list of HTTP status codes. Special cases are 2xx, 3xx, ... which match against all status codes in the range of 200-299, 300-399, ... respectively

See the header request matcher for the supported syntax.

Examples

Enable Gzip compression:

encode gzip

Enable Zstandard and Gzip compression (with Zstandard implicitly preferred, since it is first):

encode zstd gzip

And in a full site, compressing static files served by file_server:

example.com {
	root * /srv
	encode zstd gzip
	file_server
}