rfc9111

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNegativeRatio = errors.New("invalid heuristic expiration ratio (< 0)")

Functions

func CalclateExpires

func CalclateExpires(d *ResponseDirectives, resHeader http.Header, heuristicExpirationRatio float64, now time.Time) time.Time

Types

type ExtendedRule added in v0.7.0

type ExtendedRule interface {
	// Cacheable returns true and and the expiration time if the response is cacheable.
	Cacheable(req *http.Request, res *http.Response) (ok bool, age time.Duration)
}

ExtendedRule is an extended rule. Like proxy_cache_valid of NGINX. Rules are applied only when there is no Cache-Control header and the expiration time cannot be calculated. THIS IS NOT RFC 9111.

type RequestDirectives

func ParseRequestCacheControlHeader

func ParseRequestCacheControlHeader(headers []string) *RequestDirectives

ParseRequestCacheControlHeader parses the Cache-Control header of a request.

type Shared

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

Shared is a shared cache that implements RFC 9111. The following features are not implemented - Private cache. - Request directives.

func NewShared

func NewShared(opts ...SharedOption) (*Shared, error)

NewShared returns a new Shared cache handler.

func (*Shared) Handle

func (s *Shared) Handle(req *http.Request, cachedReq *http.Request, cachedRes *http.Response, do func(*http.Request) (*http.Response, error), now time.Time) (useCached bool, r *http.Response, _ error)

func (*Shared) Storable

func (s *Shared) Storable(req *http.Request, res *http.Response, now time.Time) (bool, time.Time)

Storable returns true if the response is storable in the cache.

type SharedOption

type SharedOption func(*Shared) error

SharedOption is an option for Shared.

func ExtendedRules added in v0.7.0

func ExtendedRules(rules []ExtendedRule) SharedOption

ExtendedRules sets the extended rules.

func HeuristicExpirationRatio

func HeuristicExpirationRatio(ratio float64) SharedOption

HeuristicExpirationRatio sets the heuristic expiration ratio.

func HeuristicallyCacheableStatusCodes

func HeuristicallyCacheableStatusCodes(statusCodes []int) SharedOption

HeuristicallyCacheableStatusCodes sets the heuristically cacheable status codes.

func StoreRequestWithSetCookieHeader added in v0.7.0

func StoreRequestWithSetCookieHeader() SharedOption

StoreRequestWithSetCookieHeader enables storing request with Set-Cookie header.

func UnderstoodMethods

func UnderstoodMethods(methods []string) SharedOption

UnderstoodMethods sets the understood methods.

func UnderstoodStatusCodes

func UnderstoodStatusCodes(statusCodes []int) SharedOption

UnderstoodStatusCodes sets the understood status codes.

Jump to

Keyboard shortcuts

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