cacheheader

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cacheheader provides a simple parser and serializer for http `Cache-Control` headers

Index

Constants

View Source
const DirectiveImmutable = "immutable"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#immutable

View Source
const DirectiveMaxAge = "max-age"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#max-age

View Source
const DirectiveMustRevalidate = "must-revalidate"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#must-revalidate

View Source
const DirectiveMustUnderstand = "must-understand"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#must-understand

View Source
const DirectiveNoCache = "no-cache"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#no-cache

View Source
const DirectiveNoStore = "no-store"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#no-store

View Source
const DirectiveNoTransform = "no-transform"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#no-transform

View Source
const DirectivePrivate = "private"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#private

View Source
const DirectiveProxyRevalidate = "proxy-revalidate"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#proxy-revalidate

View Source
const DirectivePublic = "public"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#public

View Source
const DirectiveSMaxAge = "s-maxage"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#s-max-age

View Source
const DirectiveStaleIfError = "stale-if-error"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-if-error

View Source
const DirectiveStaleWhileRevalidate = "stale-while-revalidate"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-while-revalidate

View Source
const HeaderAge = "age"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age

View Source
const HeaderCacheControl = "Cache-Control"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

Variables

This section is empty.

Functions

This section is empty.

Types

type Header struct {
	MaxAge               int64 `bson:"maxAge,omitempty"`               // indicates that the response remains fresh until N seconds after the response is generated.
	SMaxAge              int64 `bson:"sMaxAge,omitempty"`              // indicates how long the response remains fresh in a shared cache.
	NoCache              bool  `bson:"noCache,omitempty"`              //  indicates that the response can be stored in caches, but the response must be validated with the origin server before each reuse.
	NoStore              bool  `bson:"noStore,omitempty"`              // indicates that any caches of any kind (private or shared) should not store this response.
	NoTransform          bool  `bson:"noTransform,omitempty"`          // indicates that any intermediary (regardless of whether it implements a cache) shouldn't transform the response contents.
	MustRevalidate       bool  `bson:"mustRevalidate,omitempty"`       // indicates that the response can be stored in caches and can be reused while fresh. If the response becomes stale, it must be validated with the origin server before reuse.
	ProxyRevalidate      bool  `bson:"proxyRevalidate,omitempty"`      // The proxy-revalidate response directive is the equivalent of must-revalidate, but specifically for shared caches only.
	MustUnderstand       bool  `bson:"mustUnderstand,omitempty"`       //  indicates that a cache should store the response only if it understands the requirements for caching based on status code.
	Private              bool  `bson:"private,omitempty"`              //  indicates that the response can be stored only in a private cache (e.g. local caches in browsers).
	Public               bool  `bson:"public,omitempty"`               //  indicates that the response can be stored in a shared cache.
	Immutable            bool  `bson:"immutable,omitempty"`            // indicates that the response will not be updated while it's fresh.
	StaleWhileRevalidate int64 `bson:"staleWhileRevalidate,omitempty"` //  indicates that the cache could reuse a stale response while it revalidates it to a cache.
	StaleIfError         int64 `bson:"staleIfError,omitempty"`         //  indicates that the cache can reuse a stale response when an upstream server generates an error
	// contains filtered or unexported fields
}

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

func Parse

func Parse(header http.Header, options ...HeaderOption) Header

Parse generates a new Directive structure from an http.Header

func ParseString

func ParseString(value string, options ...HeaderOption) Header

ParseString generates a new Directive structure from a Cache-Control string

func (Header) IsCacheAllowed

func (header Header) IsCacheAllowed() bool

IsCacheAllowed returns TRUE if this header's settings allows a value to be cached

func (Header) IsNil

func (header Header) IsNil() bool

IsNil returns TRUE if no values are set within this header value.

func (Header) NotCacheAllowed

func (header Header) NotCacheAllowed() bool

NotCacheAllowed returns TRUE if this header's settings DO NOT ALLOW a value to be cached

func (Header) NotNil

func (header Header) NotNil() bool

NotNil returns TRUE if at least one value is set in the header

func (Header) String

func (header Header) String() string

String returns the string representation of this directive.

type HeaderOption

type HeaderOption func(*Header)

func AsPrivateCache

func AsPrivateCache() HeaderOption

AsPrivateCache sets the parser to treat the http.Header as a PRIVATE cache. (Default behavior)

func AsPublicCache

func AsPublicCache() HeaderOption

AsPublicCache sets the parser to treat the http.Header as a PUBLIC (or shared) cache. In this mode, some shared cache values are treated differently.

Jump to

Keyboard shortcuts

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