fscache icon indicating copy to clipboard operation
fscache copied to clipboard

Controlling headers of served cache

Open hartfordfive opened this issue 2 years ago • 1 comments

Is there a way currently to control which headers are sent with cached hit responses? For example, if you have a resource that's being served as JSON, once it's cached the "Content-Type: application/json" header is no longer added which can be problematic in some cases.

hartfordfive avatar Jun 20 '22 13:06 hartfordfive

You can chain http.Handlers together, so you can wrap the cached Handler and set the headers in the outer wrapper.

ch := fscache.Handler(cache, myExpensiveHandler)
withHeaders := http.HandlerFunc(...) {
  .... set headers like normal...
  ch.ServeHttp(rw, req)
}

djherbis avatar Jun 20 '22 15:06 djherbis