diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-12-06 17:53:57 -0800 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-12-06 17:53:57 -0800 |
commit | f2fc4db1ea0dbf4a1f75fb3e52b64e6f529e5e44 (patch) | |
tree | 7883ac215fd18966b8a1919c24339ec430bddac3 /system/admin/cache.go | |
parent | 64050ef8065bccdef0aab1748040995c637fe9ed (diff) |
adding cache (client-based, Etag) to API responses in addition to static files uploaded
Diffstat (limited to 'system/admin/cache.go')
-rw-r--r-- | system/admin/cache.go | 28 |
1 files changed, 0 insertions, 28 deletions
diff --git a/system/admin/cache.go b/system/admin/cache.go deleted file mode 100644 index 2abdb26..0000000 --- a/system/admin/cache.go +++ /dev/null @@ -1,28 +0,0 @@ -package admin - -import ( - "fmt" - "net/http" - "strings" - - "github.com/bosssauce/ponzu/system/db" -) - -// CacheControl sets the default cache policy on static asset responses -func CacheControl(next http.Handler) http.Handler { - return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - etag := db.ConfigCache("etag") - policy := fmt.Sprintf("max-age=%d, public, must-revalidate, proxy-revalidate", 60*60*24*30) - res.Header().Add("Etag", etag) - res.Header().Add("Cache-Control", policy) - - if match := res.Header().Get("If-None-Match"); match != "" { - if strings.Contains(match, etag) { - res.WriteHeader(http.StatusNotModified) - return - } - } - - next.ServeHTTP(res, req) - }) -} |