Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster committed Apr 13, 2022
1 parent fb405a6 commit 23aa27a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cmd/dkvsrv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"github.com/flipkart-incubator/dkv/meta"
"io"
"io/ioutil"
"log"
Expand All @@ -16,12 +15,14 @@ import (
"strings"
"syscall"

"github.com/flipkart-incubator/dkv/internal"
"github.com/flipkart-incubator/dkv/meta"

"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"gopkg.in/ini.v1"

"github.com/flipkart-incubator/dkv/internal"
"github.com/flipkart-incubator/dkv/internal/discovery"
"github.com/flipkart-incubator/dkv/internal/master"
"github.com/flipkart-incubator/dkv/internal/opts"
Expand Down Expand Up @@ -525,7 +526,7 @@ func setupHttpServer() {
//Admin UI
liveMode := meta.Release == "Development"
fileSystem := internal.GetWWWFileSystem(liveMode)
router.PathPrefix("/admin/").Handler(http.StripPrefix("/admin/", http.FileServer(fileSystem)))
router.PathPrefix("/admin/").Handler(http.StripPrefix("/admin/", internal.NoCache(http.FileServer(fileSystem))))

http.Handle("/", router)
http.ListenAndServe(config.HttpListenAddr, nil)
Expand Down
39 changes: 39 additions & 0 deletions internal/www.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"runtime"
"time"
)

//go:embed www
Expand Down Expand Up @@ -47,3 +48,41 @@ func GetWWWFileSystem(develMode bool) http.FileSystem {

return http.FS(fSys)
}

var epoch = time.Unix(0, 0).Format(time.RFC1123)

var noCacheHeaders = map[string]string{
"Expires": epoch,
"Cache-Control": "no-cache, private, max-age=0",
"Pragma": "no-cache",
"X-Accel-Expires": "0",
}

var etagHeaders = []string{
"ETag",
"If-Modified-Since",
"If-Match",
"If-None-Match",
"If-Range",
"If-Unmodified-Since",
}

func NoCache(h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
// Delete any ETag headers that may have been set
for _, v := range etagHeaders {
if r.Header.Get(v) != "" {
r.Header.Del(v)
}
}

// Set our NoCache headers
for k, v := range noCacheHeaders {
w.Header().Set(k, v)
}

h.ServeHTTP(w, r)
}

return http.HandlerFunc(fn)
}

0 comments on commit 23aa27a

Please sign in to comment.