add no-cache to Cache-Control on static files

This commit is contained in:
Umputun
2021-01-15 14:55:32 -06:00
parent 758c6bb1b2
commit 0dd3cd93ee
2 changed files with 2 additions and 3 deletions
+1 -2
View File
@@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"
"sync"
"time"
@@ -587,7 +586,7 @@ func cacheControl(expiration time.Duration, version string) func(http.Handler) h
fn := func(w http.ResponseWriter, r *http.Request) {
e := `"` + etag(r, version) + `"`
w.Header().Set("Etag", e)
w.Header().Set("Cache-Control", "max-age="+strconv.Itoa(int(expiration.Seconds())))
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d, no-cache", int(expiration.Seconds())))
if match := r.Header.Get("If-None-Match"); match != "" {
if strings.Contains(match, e) {
+1 -1
View File
@@ -326,7 +326,7 @@ func TestRest_cacheControl(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode)
t.Logf("%+v", resp.Header)
assert.Equal(t, `"`+tt.etag+`"`, resp.Header.Get("Etag"))
assert.Equal(t, `max-age=`+strconv.Itoa(int(tt.exp.Seconds())), resp.Header.Get("Cache-Control"))
assert.Equal(t, `max-age=`+strconv.Itoa(int(tt.exp.Seconds()))+", no-cache", resp.Header.Get("Cache-Control"))
})
}