From 872c64dd79bb1bc0e10aa8e2021710e4fb42f13d Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Sat, 7 Feb 2015 10:09:59 -0800 Subject: [PATCH] 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. --- core/corehttp/gateway_handler.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index 6c5f70818..4fcca2421 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -209,14 +209,20 @@ func (i *gatewayHandler) getHandler(w http.ResponseWriter, r *http.Request) { // set these headers _after_ the error, for we may just not have it // and dont want the client to cache a 500 response... - w.Header().Set("Etag", etag) - w.Header().Set("Cache-Control", "public, max-age=29030400") + // and only if it's /ipfs! + // TODO: break this out when we split /ipfs /ipns routes. + modtime := time.Now() + if strings.HasPrefix(urlPath, IpfsPathPrefix) { + w.Header().Set("Etag", etag) + w.Header().Set("Cache-Control", "public, max-age=29030400") + + // set modtime to a really long time ago, since files are immutable and should stay cached + modtime = time.Unix(1, 0) + } if err == nil { defer dr.Close() _, name := gopath.Split(urlPath) - // set modtime to a really long time ago, since files are immutable and should stay cached - modtime := time.Unix(1, 0) http.ServeContent(w, r, name, modtime, dr) return }