diff --git a/README.md b/README.md index 3b03b64..a915af1 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,10 @@ webtools.SetRobotsTag(w, webtools.RobotsYesIndex) webtools.SetCacheControl(w, 24 * time.Hour) ``` +```go +webtools.DisableCacheControl(w) +``` + - `Authorization` ```go diff --git a/headers.go b/headers.go index ce42ce8..bd9b9c6 100644 --- a/headers.go +++ b/headers.go @@ -61,6 +61,12 @@ func SetCacheControl(w http.ResponseWriter, ttl time.Duration) { w.Header().Add("Cache-Control", s) } +// DisableCacheControl sets the Cache-Control header on w to no-store, +// instructing intermediate caches to not store the response. +func DisableCacheControl(w http.ResponseWriter) { + w.Header().Add("Cache-Control", "no-store") +} + // SetBasicAuth sets the Authorization header on r, using the given username // and password. // diff --git a/headers_test.go b/headers_test.go index 7aef8cb..60df48f 100644 --- a/headers_test.go +++ b/headers_test.go @@ -18,6 +18,14 @@ func Test_SetCacheControl(t *testing.T) { must.Eq(t, "public, max-age=240", w.Header().Get("Cache-Control")) } +func Test_DisableCacheControl(t *testing.T) { + t.Parallel() + + w := httptest.NewRecorder() + DisableCacheControl(w) + must.Eq(t, "no-store", w.Header().Get("Cache-Control")) +} + func Test_SetContentType(t *testing.T) { t.Parallel()