compression

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package compression coordinates content-coding selection for response compression plugins. Plugins register their route-owned offers before the downstream handler writes the final response; the shared state then makes a single, order-independent decision.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coding

type Coding string
const (
	Identity Coding = "identity"
	Gzip     Coding = "gzip"
	Deflate  Coding = "deflate"
	Brotli   Coding = "br"
)

type Decision

type Decision struct {
	Coding          Coding
	NotAcceptable   bool
	Vary            bool
	IdentityAllowed bool
}

type Offer

type Offer struct {
	Coding   Coding
	Rank     int
	Eligible func(ResponseMeta) bool
}

type ResponseMeta

type ResponseMeta struct {
	Method string
	Status int
	Header http.Header
}

type State

type State struct {
	// contains filtered or unexported fields
}

State is the per-request offer set and frozen negotiation result. The mutex covers both registration and decision so a late registration cannot race with, or mutate, a result that has already been selected.

func Register

func Register(r *http.Request, offers ...Offer) (*http.Request, *State)

Register adds offers to the request's shared negotiation state. The returned request carries the state in its context and must be passed to the downstream handler. Once Decide has frozen the state, later registrations are deliberately ignored so repeated middleware callbacks remain idempotent.

func (*State) Decide

func (s *State) Decide(meta ResponseMeta) Decision

Decide freezes the complete offer set and returns the same result for every subsequent call. Eligibility is evaluated against the final response metadata supplied by the caller.

Jump to

Keyboard shortcuts

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