contentenc

package
v1.162.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

View Source
const (
	EncodingBrotli = "br"
	EncodingGzip   = "gzip"
)

Encoding names the forms Respond sends.

View Source
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

func Accepted(acceptEncoding string) (br, gz bool)

Accepted reads which compressed forms an Accept-Encoding allows. An entry whose q is 0 refuses that form.

func Brotli

func Brotli(body []byte) ([]byte, error)

Brotli is body's brotli form.

func Compressible

func Compressible(contentType string) bool

Compressible reports whether a file of the media type is worth compressing.

func Gzip

func Gzip(body []byte) ([]byte, error)

Gzip is body's gzip form.

func Respond added in v1.162.1

func Respond(r *http.Request, h http.Header, status int, body []byte, secret bool) []byte

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

func Worthwhile(original, compressed int) bool

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.

Jump to

Keyboard shortcuts

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