rfc

package
v0.0.0-...-fd6c280 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDateHeader = errors.New("no Date header")

ErrNoDateHeader indicates that the HTTP headers contained no Date header.

Functions

func CachableStatusCode

func CachableStatusCode(statusCode int) bool

func CachedResponse

func CachedResponse(c types.AbstractProviderInterface, req *http.Request, cachedKey string, transport types.TransportInterface) (*http.Response, bool, error)

CachedResponse returns the cached http.Response for req if present, and nil otherwise.

func GetVariedCacheKey

func GetVariedCacheKey(req *http.Request, headers []string) string

GetVariedCacheKey returns the varied cache key for req and resp.

func HitStaleCache

func HitStaleCache(h *http.Header, ttl time.Duration)

HitStaleCache set hit and manage age header too

func IsVaryCacheable

func IsVaryCacheable(req *http.Request) bool

IsVaryCacheable determines if it's cacheable

func MissCache

func MissCache(set func(key, value string), req *http.Request, reason string)

MissCache set miss fwd

func SetCacheStatusEventually

func SetCacheStatusEventually(resp *http.Response) *http.Response

SetCacheStatusEventually eventually set cache status header

func SetRequestCacheStatus

func SetRequestCacheStatus(h *http.Header, header, cacheName string)

SetRequestCacheStatus set the Cache-Status fwd=request

func ValidateCacheControl

func ValidateCacheControl(r *http.Response) bool

ValidateCacheControl check the Cache-Control header

func ValidateMaxAgeCachedResponse

func ValidateMaxAgeCachedResponse(req *http.Request, res *http.Response) *http.Response

func ValidateMaxAgeCachedStaleResponse

func ValidateMaxAgeCachedStaleResponse(req *http.Request, res *http.Response, addTime int) *http.Response

Types

type VaryTransport

type VaryTransport struct {
	*types.Transport
}

VaryTransport type

func NewTransport

func NewTransport(p types.AbstractProviderInterface, ykeyStorage *ykeys.YKeyStorage, surrogateStorage providers.SurrogateInterface) *VaryTransport

NewTransport returns a new Transport with the provided Cache implementation and MarkCachedResponses set to true

func (*VaryTransport) BaseRoundTrip

func (t *VaryTransport) BaseRoundTrip(req *http.Request) (string, bool, *http.Response)

BaseRoundTrip is the base for RoundTrip

func (*VaryTransport) GetCoalescingLayerStorage

func (t *VaryTransport) GetCoalescingLayerStorage() *types.CoalescingLayerStorage

GetCoalescingLayerStorage get the coalescing layer storage

func (*VaryTransport) GetProvider

GetProvider returns the associated provider

func (*VaryTransport) GetSurrogateKeys

func (t *VaryTransport) GetSurrogateKeys() providers.SurrogateInterface

GetSurrogateKeys get the surrogate keys storage

func (*VaryTransport) GetYkeyStorage

func (t *VaryTransport) GetYkeyStorage() *ykeys.YKeyStorage

GetYkeyStorage get the ykeys storage

func (*VaryTransport) RoundTrip

func (t *VaryTransport) RoundTrip(req *http.Request) (resp *http.Response, err error)

RoundTrip takes a Request and returns a Response

If there is a fresh Response already in cache, then it will be returned without connecting to the server.

If there is a stale Response, then any validators it contains will be set on the new request to give the server a chance to respond with NotModified. If this happens, then the cached Response will be returned.

func (*VaryTransport) SetCache

func (t *VaryTransport) SetCache(key string, resp *http.Response, ccValue string) bool

SetCache set the cache

func (*VaryTransport) SetSurrogateKeys

func (t *VaryTransport) SetSurrogateKeys(s providers.SurrogateInterface)

SetSurrogateKeys set the surrogate keys storage

func (*VaryTransport) SetURL

func (t *VaryTransport) SetURL(url configurationtypes.URL)

SetURL set the URL

func (*VaryTransport) UpdateCacheEventually

func (t *VaryTransport) UpdateCacheEventually(req *http.Request) (*http.Response, error)

UpdateCacheEventually will handle Request and update the previous one in the cache provider

Jump to

Keyboard shortcuts

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