From 844c5996ffc5121c4fc875f0ea3c8d96195b7202 Mon Sep 17 00:00:00 2001 From: Danny Date: Wed, 13 Jun 2018 11:15:18 +0200 Subject: [PATCH] set 'Tk: N' header on resources loaded by client. #65 --- pkg/api/collect.go | 7 ++++++- pkg/api/routes.go | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/api/collect.go b/pkg/api/collect.go index 1d9389b..06c75dd 100644 --- a/pkg/api/collect.go +++ b/pkg/api/collect.go @@ -122,11 +122,16 @@ func (api *API) NewCollectHandler() http.Handler { return err } - // don't you cache this + // indicate that we're not tracking user data, see https://github.com/usefathom/fathom/issues/65 + w.Header().Set("Tk", "N") + + // headers to prevent caching w.Header().Set("Content-Type", "image/gif") w.Header().Set("Expires", "Mon, 01 Jan 1990 00:00:00 GMT") w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Header().Set("Pragma", "no-cache") + + // response w.WriteHeader(http.StatusOK) // 1x1 px transparent GIF diff --git a/pkg/api/routes.go b/pkg/api/routes.go index 164d32c..f8fb537 100644 --- a/pkg/api/routes.go +++ b/pkg/api/routes.go @@ -29,10 +29,18 @@ func (api *API) Routes() *mux.Router { // static assets & 404 handler box := packr.NewBox("./../../assets/build") - r.Path("/tracker.js").Handler(serveFileHandler(&box, "js/tracker.js")) + r.Path("/tracker.js").Handler(serveTrackerFile(&box)) r.Path("/").Handler(serveFileHandler(&box, "index.html")) r.PathPrefix("/assets").Handler(http.StripPrefix("/assets", http.FileServer(box))) r.NotFoundHandler = NotFoundHandler(&box) return r } + +func serveTrackerFile(box *packr.Box) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Tk", "N") + next := serveFile(box, "js/tracker.js") + next.ServeHTTP(w, r) + }) +}