Skip to content
This repository has been archived by the owner on Apr 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #21 from hnakamur/fix_x_cache_header
Browse files Browse the repository at this point in the history
Set X-Cache header properly
  • Loading branch information
lox committed Feb 23, 2016
2 parents 6b56d0d + cc488df commit 7518d57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cli/httpcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func init() {
func main() {
proxy := &httputil.ReverseProxy{
Director: func(r *http.Request) {
r.URL.Scheme = "http"
r.URL.Host = "127.0.0.1:80"
},
}

Expand Down
4 changes: 2 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
}

debugf("serving from cache")
res.Header().Set(CacheHeader, "HIT")
h.serveResource(res, rw, cReq)
rw.Header().Set(CacheHeader, "HIT")

if err := res.Close(); err != nil {
errorf("Error closing resource: %s", err.Error())
Expand Down Expand Up @@ -224,6 +224,7 @@ func (h *Handler) passUpstream(w http.ResponseWriter, r *cacheRequest) {

t := Clock()
debugf("passing request upstream")
rw.Header().Set(CacheHeader, "MISS")
h.upstream.ServeHTTP(rw, r.Request)
res := rw.Resource()
debugf("upstream responded in %s", Clock().Sub(t).String())
Expand All @@ -240,7 +241,6 @@ func (h *Handler) passUpstream(w http.ResponseWriter, r *cacheRequest) {
debugf("error calculating corrected age: %s", err.Error())
}

rw.Header().Set(CacheHeader, "MISS")
rw.Header().Set(ProxyDateHeader, Clock().Format(http.TimeFormat))
h.storeResource(res, r)
}
Expand Down

0 comments on commit 7518d57

Please sign in to comment.