Skip to content

Commit

Permalink
fix(issue-198): Support 304 response (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak authored Apr 6, 2022
1 parent 896cb46 commit bf3b204
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plugins/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ func (r *CustomWriter) Send() (int, error) {
}
}
r.Rw.WriteHeader(r.Response.StatusCode)
b, _ := ioutil.ReadAll(r.Response.Body)
var b []byte

if r.Response.Body != nil {
b, _ = ioutil.ReadAll(r.Response.Body)
}
return r.Rw.Write(b)
}

Expand Down
7 changes: 7 additions & 0 deletions plugins/caddy/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ route /cache-maxage {
respond "Hello, max-age!"
}

route /not-modified {
cache {
ttl 5s
}
reverse_proxy 127.0.0.1:9000
}

route /no-reverse-proxy {
cache
reverse_proxy 127.0.0.1:9000
Expand Down
3 changes: 3 additions & 0 deletions rfc/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ func commonVaryMatchesVerification(cachedResp *http.Response, req *http.Request)
// UpdateCacheEventually will handle Request and update the previous one in the cache provider
func (t *VaryTransport) UpdateCacheEventually(req *http.Request) (*http.Response, error) {
if req.Response.Header.Get("Cache-Control") == "" && t.ConfigurationURL.DefaultCacheControl != "" {
if req.Response.Header == nil {
req.Response.Header = http.Header{}
}
req.Response.Header.Set("Cache-Control", t.ConfigurationURL.DefaultCacheControl)
}

Expand Down

0 comments on commit bf3b204

Please sign in to comment.