From 26c9fb0cc32f30a8eb71eb92e42a048fae290b9f Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Fri, 14 Feb 2014 13:24:12 -0700 Subject: [PATCH] fix for #70 to prevent caching build images --- cmd/droned/drone.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/droned/drone.go b/cmd/droned/drone.go index 86b6ba13f..947b63e07 100644 --- a/cmd/droned/drone.go +++ b/cmd/droned/drone.go @@ -73,7 +73,18 @@ func setupDatabase() { func setupStatic() { box := rice.MustFindBox("assets") http.Handle("/css/", http.FileServer(box.HTTPBox())) - http.Handle("/img/", http.FileServer(box.HTTPBox())) + + // we need to intercept all attempts to serve images + // so that we can add a cache-control settings + var images = http.FileServer(box.HTTPBox()) + http.HandleFunc("/img/", func(w http.ResponseWriter, r *http.Request) { + if strings.HasPrefix(r.URL.Path, "/img/build_") { + w.Header().Add("Cache-Control", "no-cache") + } + + // serce images + images.ServeHTTP(w, r) + }) } // setup routes for serving dynamic content. @@ -164,8 +175,6 @@ func setupHandlers() { // the first time a page is requested we should record // the scheme and hostname. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - // get the hostname and scheme - // our multiplexer is a bit finnicky and therefore requires // us to strip any trailing slashes in order to correctly // find and match a route.