Skip to content

Commit

Permalink
Support force cache even when server doesn't set the Date header
Browse files Browse the repository at this point in the history
This fixes a bug where when a upstream server doesn't set a Date
header the response will be cached but then once the cache is
expired it never gets refreshed because parseResponseHeaders
returns a no date header error

This also makes it so that the force_cache_duration_seconds
is respected when an upstream returns a 304 not modified

Signed-off-by: Peter <[email protected]>
  • Loading branch information
c2zwdjnlcg committed Aug 22, 2023
1 parent de896d9 commit 218979d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions topdown/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,11 @@ func (c *interQueryCache) checkHTTPSendInterQueryCache() (ast.Value, error) {

headers, err := parseResponseHeaders(cachedRespData.Headers)
if err != nil {
return nil, err
if forceCaching(c.forceCacheParams) {
headers = &responseHeaders{}
} else {
return nil, err
}
}

// check with the server if the stale response is still up-to-date.
Expand All @@ -864,11 +868,16 @@ func (c *interQueryCache) checkHTTPSendInterQueryCache() (ast.Value, error) {
}
}

expiresAt, err := expiryFromHeaders(result.Header)
if err != nil {
return nil, err
if forceCaching(c.forceCacheParams) {
createdAt := getCurrentTime(c.bctx)
cachedRespData.ExpiresAt = createdAt.Add(time.Second * time.Duration(c.forceCacheParams.forceCacheDurationSeconds))
} else {
expiresAt, err := expiryFromHeaders(result.Header)
if err != nil {
return nil, err
}
cachedRespData.ExpiresAt = expiresAt
}
cachedRespData.ExpiresAt = expiresAt

cachingMode, err := getCachingMode(c.key)
if err != nil {
Expand Down

0 comments on commit 218979d

Please sign in to comment.