{"modulePath":"github.com/sourcegraph/apiproxy","version":"v0.0.0-20131001030531-ee6ce9aecff2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package apiproxy\n\nPackage apiproxy proxies HTTP/REST APIs and supports configurable cache timeouts, etc.\n\n## Variables\n\n```go\nvar NeverRevalidate = ValidatorFunc(func(_ *url.URL, _ time.Duration) bool {\n\treturn true\n})\n```\nNeverRevalidate 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.\n\n```go\nvar NoCache = http.Header{\"Cache-Control\": []string{\"no-cache\"}}\n```\n\n## Functions\n\n```go\nfunc NewCachingSingleHostReverseProxy(target *url.URL, cache httpcache.Cache) *httputil.ReverseProxy\n```\nNewCachingSingleHostReverseProxy constructs a caching reverse proxy handler for target. If cache is nil, a volatile, in-memory cache is used.\n\n```go\nfunc NewSingleHostReverseProxy(url *url.URL) *httputil.ReverseProxy\n```\nNewSingleHostReverseProxy wraps net/http/httputil.NewSingleHostReverseProxy and sets the Host header based on the target URL.\n\n## Types\n\n```go\ntype PathMatchValidator map[*regexp.Regexp]time.Duration\n```\nPathMatchValidator is a map of path regexps to the maximum age of resources matching one of those regexps.\n\n```go\nfunc (v PathMatchValidator) Valid(url *url.URL, age time.Duration) bool\n```\nValid implements Validator.\n\n```go\ntype RequestModifyingTransport struct {\n\n\t// Transport is the underlying transport. If nil, net/http.DefaultTransport\n\t// is used.\n\tTransport http.RoundTripper\n\t// contains filtered or unexported fields\n}\n```\nRequestModifyingTransport is an implementation of net/http.RoundTripper that allows headers to be overwritten on requests matching certain predicates.\n\nIt gives more control over HTTP requests (e.g., caching) when using libraries whose only HTTP configuration point is a http.Client or http.RoundTripper.\n\n```go\nfunc (t *RequestModifyingTransport) Override(requestURI *regexp.Regexp, setHeaders http.Header, runOnlyOnce bool)\n```\nOverride 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.\n\n```go\nfunc (t *RequestModifyingTransport) RoundTrip(req *http.Request) (resp *http.Response, err error)\n```\nRoundTrip implements net/http.RoundTripper.\n\n```go\ntype RevalidationTransport struct {\n\t// Check.Valid is called on each request in RoundTrip. If it returns true,\n\t// RoundTrip synthesizes and returns an HTTP 304 Not Modified response.\n\t// Otherwise, the request is passed through to the underlying transport.\n\tCheck Validator\n\n\t// Transport is the underlying transport. If nil, net/http.DefaultTransport is used.\n\tTransport http.RoundTripper\n}\n```\nRevalidationTransport is an implementation of net/http.RoundTripper that permits custom behavior with respect to cache entry revalidation for resources on the target server.\n\nIf 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.\n\nIf the request does not contain cache validators, then it is passed to the underlying transport.\n\n```go\nfunc (t *RevalidationTransport) RoundTrip(req *http.Request) (resp *http.Response, err error)\n```\nRoundTrip takes a Request and returns a Response.\n\n```go\ntype Validator interface {\n\tValid(url *url.URL, age time.Duration) bool\n}\n```\nValidators 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).\n\n```go\ntype ValidatorFunc func(url *url.URL, age time.Duration) bool\n```\nValidatorFunc 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.\n\n```go\nfunc (f ValidatorFunc) Valid(url *url.URL, age time.Duration) bool\n```\nValid implements Validator.\n\n","path":"github.com/sourcegraph/apiproxy","name":"apiproxy","synopsis":"Package apiproxy proxies HTTP/REST APIs and supports configurable cache timeouts, etc.","isRedistributable":true}
