Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ webtools.SetRobotsTag(w, webtools.RobotsYesIndex)
webtools.SetCacheControl(w, 24 * time.Hour)
```

```go
webtools.DisableCacheControl(w)
```

- `Authorization`

```go
Expand Down
6 changes: 6 additions & 0 deletions headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
8 changes: 8 additions & 0 deletions headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down