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 ¶
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 ¶
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 ¶
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.