http: Response refers to requested ETag on 304, not 200

Otherwise a 200 response without an ETag could be incorrectly associated
to previous content in the following scenario:

* The remote server had in the past responded with an ETag for this
  resource, which was cached.
  - (Otherwise, onlyETag would be empty)
* That was the only ETag cached for this resource.
  - (Otherwise, onlyETag would be empty)
* The remote server then stopped supporting ETag/If-None-Match for this
  resource at all.
  - (Otherwise, it would respond with a 304 or a 200+ETag)

Signed-off-by: Robert Estelle <robertestelle@gmail.com>
v0.7
Robert Estelle 2019-09-04 20:22:48 -04:00
parent c63c6f9683
commit 6ff0868457
1 changed files with 4 additions and 1 deletions

View File

@ -181,7 +181,10 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, index int) (string, b
if err == nil {
if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotModified {
respETag := resp.Header.Get("ETag")
if respETag == "" && onlyETag != "" {
// If a 304 is returned without an ETag and we had only sent one ETag,
// the response refers to the ETag we asked about.
if respETag == "" && onlyETag != "" && resp.StatusCode == http.StatusNotModified {
respETag = onlyETag
}
si, ok := m[respETag]