Documentation ¶
Overview ¶
Package apiproxy proxies HTTP/REST APIs and supports configurable cache timeouts, etc.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NeverRevalidate = ValidatorFunc(func(_ *url.URL, _ time.Duration) bool { return true })
NeverRevalidate is a Validator for use with RevalidationTransport that causes HTTP requests to never revalidate cache entries. If a cache entry exists, it will always be used, even if it is expired.
var NoCache = http.Header{"Cache-Control": []string{"no-cache"}}
Functions ¶
func NewCachingSingleHostReverseProxy ¶
func NewCachingSingleHostReverseProxy(target *url.URL, cache httpcache.Cache) *httputil.ReverseProxy
NewCachingSingleHostReverseProxy constructs a caching reverse proxy handler for target. If cache is nil, a volatile, in-memory cache is used.
func NewSingleHostReverseProxy ¶
func NewSingleHostReverseProxy(url *url.URL) *httputil.ReverseProxy
NewSingleHostReverseProxy wraps net/http/httputil.NewSingleHostReverseProxy and sets the Host header.
Types ¶
type PathMatchValidator ¶
PathMatchValidator is a map of path regexps to the maximum age of resources matching one of those regexps.
type RequestModifyingTransport ¶
type RequestModifyingTransport struct { // Transport is the underlying transport. If nil, net/http.DefaultTransport // is used. Transport http.RoundTripper // contains filtered or unexported fields }
RequestModifyingTransport is an implementation of net/http.RoundTripper that allows headers to be overwritten on requests matching certain predicates.
It gives more control over HTTP requests (e.g., caching) when using libraries whose only HTTP configuration point is a http.Client or http.RoundTripper.
func (*RequestModifyingTransport) Override ¶
func (t *RequestModifyingTransport) Override(requestURI *regexp.Regexp, setHeaders http.Header, runOnlyOnce bool)
Override instructs the transport to set the specified headers (overwriting existing headers of the same name) on a GET or HEAD request whose request URI matches the regexp. If runOnlyOnce is true, the override will be deleted after execution (and won't affect any future requests); otherwise, it will remain in effect for the lifetime of the transport.
type RevalidationTransport ¶
type RevalidationTransport struct { // Check.Valid is called on each request in RoundTrip. If it returns true, // RoundTrip synthesizes and returns an HTTP 304 Not Modified response. // Otherwise, the request is passed through to the underlying transport. Check Validator // Transport is the underlying transport. If nil, net/http.DefaultTransport is used. Transport http.RoundTripper }
RevalidationTransport is an implementation of net/http.RoundTripper that permits custom behavior with respect to cache entry revalidation for resources on the target server.
If the request contains cache validators (an If-None-Match or If-Modified-Since header), then Check.Valid is called to determine whether the cache entry should be revalidated (by being passed to the underlying transport). In this way, the Check Validator can effectively extend or shorten cache age limits.
If the request does not contain cache validators, then it is passed to the underlying transport.
type Validator ¶
Validators are used to determine whether a cache entry for a URL is still valid at a certain age. They are used to set custom max-ages for cache entries (e.g., to extend the max-age of a certain API resource that an application knows to be rarely updated).
type ValidatorFunc ¶
ValidatorFunc is an adapter type to allow the use of ordinary functions as validators. If f is a function with the appropriate signature, ValidatorFunc(f) is a Validator object that calls f.