From abf5ab340ed76792214ae80c62df7abe0ad1b8a8 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 15 Oct 2019 14:07:10 -0600 Subject: caddyhttp: Improve ResponseRecorder to buffer headers --- modules/caddyhttp/httpcache/httpcache.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'modules/caddyhttp/httpcache/httpcache.go') diff --git a/modules/caddyhttp/httpcache/httpcache.go b/modules/caddyhttp/httpcache/httpcache.go index 1b2cfd2..0b49c7e 100644 --- a/modules/caddyhttp/httpcache/httpcache.go +++ b/modules/caddyhttp/httpcache/httpcache.go @@ -130,8 +130,7 @@ func (c *Cache) getter(ctx groupcache.Context, key string, dest groupcache.Sink) // we need to record the response if we are to cache it; only cache if // request is successful (TODO: there's probably much more nuance needed here) - var rr caddyhttp.ResponseRecorder - rr = caddyhttp.NewResponseRecorder(combo.rw, buf, func(status int) bool { + rr := caddyhttp.NewResponseRecorder(combo.rw, buf, func(status int, header http.Header) bool { shouldBuf := status < 300 if shouldBuf { @@ -141,7 +140,7 @@ func (c *Cache) getter(ctx groupcache.Context, key string, dest groupcache.Sink) // the rest will be the body, which will be written // implicitly for us by the recorder err := gob.NewEncoder(buf).Encode(headerAndStatus{ - Header: rr.Header(), + Header: header, Status: status, }) if err != nil { -- cgit v1.2.3