diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-03-06 23:24:09 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-03-06 23:26:13 -0700 |
commit | b216d285dfe8784796d3f6597545c59aa4bec279 (patch) | |
tree | 92a949a75c1460b0aabac97c7d2831222d91a460 /modules/caddyhttp/httpcache | |
parent | 3f5d27cd5da8f3ad53e4b794d34703922c9b824e (diff) | |
parent | b8cba62643abf849411856bd92c42b59b98779f4 (diff) |
Merge branch 'certmagic-refactor' into v2
Diffstat (limited to 'modules/caddyhttp/httpcache')
-rw-r--r-- | modules/caddyhttp/httpcache/httpcache.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/modules/caddyhttp/httpcache/httpcache.go b/modules/caddyhttp/httpcache/httpcache.go index f8bdde8..605a183 100644 --- a/modules/caddyhttp/httpcache/httpcache.go +++ b/modules/caddyhttp/httpcache/httpcache.go @@ -16,6 +16,7 @@ package httpcache import ( "bytes" + "context" "encoding/gob" "fmt" "io" @@ -108,7 +109,8 @@ func (c *Cache) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp return next.ServeHTTP(w, r) } - ctx := getterContext{w, r, next} + getterCtx := getterContext{w, r, next} + ctx := context.WithValue(r.Context(), getterContextCtxKey, getterCtx) // TODO: rigorous performance testing @@ -152,8 +154,8 @@ func (c *Cache) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp return nil } -func (c *Cache) getter(ctx groupcache.Context, key string, dest groupcache.Sink) error { - combo := ctx.(getterContext) +func (c *Cache) getter(ctx context.Context, key string, dest groupcache.Sink) error { + combo := ctx.Value(getterContextCtxKey).(getterContext) // the buffer will store the gob-encoded header, then the body buf := bufPool.Get().(*bytes.Buffer) @@ -228,6 +230,10 @@ var errUncacheable = fmt.Errorf("uncacheable") const groupName = "http_requests" +type ctxKey string + +const getterContextCtxKey ctxKey = "getter_context" + // Interface guards var ( _ caddy.Provisioner = (*Cache)(nil) |