Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CachingRoundTripper ¶
type CachingRoundTripper struct {
Cache RequestResponseCache
// this is RoundTripper to use to make the actual request
// if nil, will use http.DefaultTransport
RoundTripper http.RoundTripper
// for diagnostics, you can check how many http requests
// were served from a cache and how many from network requests
RequestsFromCache int `json:"-"`
RequestsNotFromCache int `json:"-"`
}
CachingRoundTripper is a http round-tripper that implements caching of past requests
func GetCachingRoundTripper ¶
func GetCachingRoundTripper(c *http.Client) *CachingRoundTripper
GetCachingRoundTripper returns CachingRoundTripper from c.Transport
func NewRoundTripper ¶
func NewRoundTripper(cache RequestResponseCache) *CachingRoundTripper
NewRoundTripper creates http.RoundTripper that caches requests
type MemoryCache ¶
type MemoryCache struct {
// CachedRequests remembers past requests and their responses
CachedRequests []*RequestResponse `json:"cached_requests"`
// if true, will not return cached responses (but will still
// record requests / responses)
// Useful for tracing requests (but only those that return 200)
DisableRespondingFromCache bool
// if true, when comparing body of the request, and the body
// is json, we'll normalize JSON
CompareNormalizedJSONBody bool
}
MemoryCache remembers past requests and responses
func NewMemoryCache ¶
func NewMemoryCache() *MemoryCache
NewMemoryCache returns a cache for http requests
func (*MemoryCache) Add ¶
func (c *MemoryCache) Add(rr *RequestResponse)
Add remembers a given RequestResponse
func (*MemoryCache) FindCachedResponse ¶
func (c *MemoryCache) FindCachedResponse(r *http.Request, cachedBody *[]byte) (*RequestResponse, error)
FindCachedResponse returns
type RequestResponse ¶
type RequestResponse struct {
Method string `json:"method"`
URL string `json:"url"`
Body []byte `json:"body"`
Response []byte `json:"response"`
Header http.Header `json:"header"`
}
RequestResponse is a cache entry. It remembers important details of the request and response
type RequestResponseCache ¶
type RequestResponseCache interface {
Add(rr *RequestResponse)
FindCachedResponse(r *http.Request, cachedBody *[]byte) (*RequestResponse, error)
}
RequestResponseCache defines interface
func GetCache ¶
func GetCache(c *http.Client) RequestResponseCache
GetCache gets from the client if it's a client created by us
Click to show internal directories.
Click to hide internal directories.