gateway: dont cache ipns paths
ipns paths are mutable and should not be cached. this error is a byproduct of the currently messy gateway route. We should split the /ipfs and /ipns routes up.
Juan Batiz-Benet committed
Feb 7, 2015 at 10:09 UTC
872c64dd79bb1bc0e10aa8e2021710e4fb42f13d
1 file changed
+10
-4
core/corehttp/gateway_handler.go
+10
-4
@@ -209,14 +209,20 @@ func (i *gatewayHandler) getHandler(w http.ResponseWriter, r *http.Request) {
209
210
// set these headers _after_ the error, for we may just not have it
211
// and dont want the client to cache a 500 response...
212
- w.Header().Set("Etag", etag)
213
- w.Header().Set("Cache-Control", "public, max-age=29030400")
212
+ // and only if it's /ipfs!
213
+ // TODO: break this out when we split /ipfs /ipns routes.
214
+ modtime := time.Now()
215
+ if strings.HasPrefix(urlPath, IpfsPathPrefix) {
216
+ w.Header().Set("Etag", etag)
217
+ w.Header().Set("Cache-Control", "public, max-age=29030400")
218
+
219
+ // set modtime to a really long time ago, since files are immutable and should stay cached
220
+ modtime = time.Unix(1, 0)
221
+ }
222
223
if err == nil {
224
defer dr.Close()
225
_, name := gopath.Split(urlPath)
218
- // set modtime to a really long time ago, since files are immutable and should stay cached
219
- modtime := time.Unix(1, 0)
226
http.ServeContent(w, r, name, modtime, dr)
227
return
228
}