Documentation ¶
Overview ¶
Package cacheheader provides a simple parser and serializer for http `Cache-Control` headers
Index ¶
Constants ¶
const DirectiveImmutable = "immutable"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#immutable
const DirectiveMaxAge = "max-age"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#max-age
const DirectiveMustRevalidate = "must-revalidate"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#must-revalidate
const DirectiveMustUnderstand = "must-understand"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#must-understand
const DirectiveNoCache = "no-cache"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#no-cache
const DirectiveNoStore = "no-store"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#no-store
const DirectiveNoTransform = "no-transform"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#no-transform
const DirectivePrivate = "private"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#private
const DirectiveProxyRevalidate = "proxy-revalidate"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#proxy-revalidate
const DirectivePublic = "public"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#public
const DirectiveSMaxAge = "s-maxage"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#s-max-age
const DirectiveStaleIfError = "stale-if-error"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-if-error
const DirectiveStaleWhileRevalidate = "stale-while-revalidate"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-while-revalidate
const HeaderAge = "age"
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age
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 ¶
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 ¶
IsCacheAllowed returns TRUE if this header's settings allows a value to be cached
func (Header) NotCacheAllowed ¶
NotCacheAllowed returns TRUE if this header's settings DO NOT ALLOW a value to be cached
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.