compress

package
v0.0.0-...-0411a9e Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package compress handles Content-Encoding compression for HTTP body inspection.

Typical usage in a response body handler:

decoded, err := compress.Decode(chunk.ContentEncoding, chunk.Data)

To prevent upstream from sending compressed responses, call RequestIdentity from the request headers handler instead:

func onReq(w *up.Writer, r *up.Request) { compress.RequestIdentity(w) }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptEncodingAllSupported

func AcceptEncodingAllSupported(acceptEncoding string) bool

AcceptEncodingAllSupported reports whether every encoding token in an Accept-Encoding header value is one that Decode can handle. Quality values (e.g. ;q=0.9) are ignored: the upstream performs actual negotiation and we will only receive an encoding that the upstream chose to use. The wildcard "*" always returns false because any encoding could be selected.

func Decode

func Decode(encoding string, data []byte) ([]byte, error)

Decode decompresses data according to the Content-Encoding header value. Supports "gzip", "deflate", "zstd", "br", "identity", and "". Returns data unchanged for identity or empty encoding.

func Encode

func Encode(encoding string, data []byte) ([]byte, error)

Encode compresses data with the given encoding. Supports "gzip", "deflate", "zstd", "br", "identity", and "".

func RequestIdentity

func RequestIdentity(h RequestHeaderSetter)

RequestIdentity sets Accept-Encoding: identity on the outgoing request so upstream responds with uncompressed bodies. Call from OnRequestHeaders. This is the preferred strategy; use Decode as a fallback for upstreams that ignore Accept-Encoding (some CDNs always compress).

Types

type RequestHeaderSetter

type RequestHeaderSetter interface {
	SetRequestHeader(name, value string)
}

RequestHeaderSetter is implemented by types that can rewrite outgoing request headers.

Jump to

Keyboard shortcuts

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