Skip to content

Commit

Permalink
Update tests and improve the Storing
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Jul 3, 2022
1 parent 4065f54 commit acb68ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 6 additions & 0 deletions plugins/caddy/httpcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func TestMaxAge(t *testing.T) {
if resp2.Header.Get("Cache-Status") != "Souin; hit; ttl=59" {
t.Errorf("unexpected Cache-Status header %v", resp2.Header.Get("Cache-Status"))
}

time.Sleep(2 * time.Second)
resp3, _ := tester.AssertGetResponse(`http://localhost:9080/cache-max-age`, 200, "Hello, max-age!")
if resp3.Header.Get("Cache-Status") != "Souin; hit; ttl=57" {
t.Errorf("unexpected Cache-Status header %v", resp2.Header.Get("Cache-Status"))
}
}

func TestSMaxAge(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions rfc/cacheStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ func manageAge(h *http.Header, ttl time.Duration) {
if h.Get(storedTTLHeader) != "" {
ttl, _ = time.ParseDuration(h.Get(storedTTLHeader))
h.Del(storedTTLHeader)
cage := correctedInitialAge(utc1, utc2)
age := strconv.Itoa(cage)
h.Set("Age", age)
ttlValue := strconv.Itoa(int(ttl.Seconds()) - cage)
h.Set("Cache-Status", "Souin; hit; ttl="+ttlValue)
}
cage := correctedInitialAge(utc1, utc2)
age := strconv.Itoa(cage)
h.Set("Age", age)
ttlValue := strconv.Itoa(int(ttl.Seconds()) - cage)
h.Set("Cache-Status", "Souin; hit; ttl="+ttlValue)
}

func setMalformedHeader(headers *http.Header, header string) {
Expand Down
3 changes: 1 addition & 2 deletions rfc/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ func (t *VaryTransport) SetCache(key string, resp *http.Response) {
}
if ma > t.ConfigurationURL.TTL.Duration {
ma = t.ConfigurationURL.TTL.Duration
} else {
resp.Header.Set(storedTTLHeader, ma.String())
}
resp.Header.Set(storedTTLHeader, ma.String())
if respBytes, err := httputil.DumpResponse(resp, true); e == nil && err == nil {
t.Provider.Set(key, respBytes, t.ConfigurationURL, ma)
}
Expand Down

0 comments on commit acb68ab

Please sign in to comment.