Documentation
¶
Overview ¶
Package contentenc is how the platform sends a file compressed: which media types are worth compressing, the gzip and brotli forms of a body, whether a form saves enough to keep, and which forms a request's Accept-Encoding allows. A site's published files (internal/site) and the portal's own build files (internal/ui, #2598) are sent by these one set of rules, and Respond is the rule for a body produced per request: an endpoint's answer in api and page mode and a form's page (#2655).
Index ¶
- Constants
- func Accepted(acceptEncoding string) (br, gz bool)
- func Brotli(body []byte) ([]byte, error)
- func Compressible(contentType string) bool
- func Gzip(body []byte) ([]byte, error)
- func Respond(r *http.Request, h http.Header, status int, body []byte, secret bool) []byte
- func Worthwhile(original, compressed int) bool
Constants ¶
const ( EncodingBrotli = "br" EncodingGzip = "gzip" )
Encoding names the forms Respond sends.
const ( // MinBytes is the smallest body worth compressing: below it the framing // costs about what the compression saves. MinBytes = 1024 )
Variables ¶
This section is empty.
Functions ¶
func Accepted ¶
Accepted reads which compressed forms an Accept-Encoding allows. An entry whose q is 0 refuses that form.
func Compressible ¶
Compressible reports whether a file of the media type is worth compressing.
func Respond ¶ added in v1.162.1
Respond is body as an answer produced for r is sent: brotli or gzip when r accepts one, the content type compresses, the body is at least MinBytes and the form saves enough, with Content-Encoding and Vary set on h; body as it is otherwise (#2655). secret says the answer may hold one of the platform's tokens beside text the requester chose, which is never compressed: its compressed length would tell an observer how well a guess matched the token (BREACH). A HEAD, a 204 or 304, and a body the handler encoded itself are sent as they are.
func Worthwhile ¶
Worthwhile reports whether a compressed form of compressed bytes saves enough over an original of original bytes to be kept and sent.
Types ¶
This section is empty.