Skip to content

Commit

Permalink
review: 15 mins -> 5 mins
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Norman <1992255+2color@users.noreply.github.com>
  • Loading branch information
hacdias and 2color committed Mar 6, 2024
1 parent b543001 commit 2a18c58
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The following emojis are used to highlight certain changes:

### Added

* `routing/http/server` now adds `Cache-Control` HTTP header to GET requests: 15 seconds for empty responses, or 15 minutes for responses with providers.
* `routing/http/server` now adds `Cache-Control` HTTP header to GET requests: 15 seconds for empty responses, or 5 minutes for responses with providers.

### Changed

Expand Down
4 changes: 2 additions & 2 deletions routing/http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func writeJSONResult(w http.ResponseWriter, method string, val interface{ Length

if val.Length() > 0 {
// There's results, cache for 5 minutes
w.Header().Set("Cache-Control", "max-age=900, public")
w.Header().Set("Cache-Control", "max-age=300, public")
} else {
// There weren't results, cache for 15 seconds
w.Header().Set("Cache-Control", "max-age=15, public")
Expand Down Expand Up @@ -526,7 +526,7 @@ func writeResultsIterNDJSON[T any](w http.ResponseWriter, resultIter iter.Result

if !hasResults {
// There's results, cache for 5 minutes
w.Header().Set("Cache-Control", "max-age=900, public")
w.Header().Set("Cache-Control", "max-age=300, public")
hasResults = true
}

Expand Down
6 changes: 3 additions & 3 deletions routing/http/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestProviders(t *testing.T) {
if empty {
require.Equal(t, "max-age=15, public", resp.Header.Get("Cache-Control"))
} else {
require.Equal(t, "max-age=900, public", resp.Header.Get("Cache-Control"))
require.Equal(t, "max-age=300, public", resp.Header.Get("Cache-Control"))
}

body, err := io.ReadAll(resp.Body)
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestPeers(t *testing.T) {
require.Equal(t, 200, resp.StatusCode)

require.Equal(t, mediaTypeJSON, resp.Header.Get("Content-Type"))
require.Equal(t, "max-age=900, public", resp.Header.Get("Cache-Control"))
require.Equal(t, "max-age=300, public", resp.Header.Get("Cache-Control"))

body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
Expand Down Expand Up @@ -270,7 +270,7 @@ func TestPeers(t *testing.T) {
require.Equal(t, 200, resp.StatusCode)

require.Equal(t, mediaTypeNDJSON, resp.Header.Get("Content-Type"))
require.Equal(t, "max-age=900, public", resp.Header.Get("Cache-Control"))
require.Equal(t, "max-age=300, public", resp.Header.Get("Cache-Control"))

body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
Expand Down

0 comments on commit 2a18c58

Please sign in to comment.