Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: handle weak etags on comparisons #2629

Merged
merged 1 commit into from
Feb 14, 2022
Merged
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
10 changes: 8 additions & 2 deletions source/http/httpsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, g session.Group, inde
resp, err := client.Do(req)
if err == nil {
if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotModified {
respETag := resp.Header.Get("ETag")
respETag := etagValue(resp.Header.Get("ETag"))

// If a 304 is returned without an ETag and we had only sent one ETag,
// the response refers to the ETag we asked about.
Expand Down Expand Up @@ -212,7 +212,7 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, g session.Group, inde
return "", "", nil, false, errors.Errorf("invalid response status %d", resp.StatusCode)
}
if resp.StatusCode == http.StatusNotModified {
respETag := resp.Header.Get("ETag")
respETag := etagValue(resp.Header.Get("ETag"))
if respETag == "" && onlyETag != "" {
respETag = onlyETag

Expand Down Expand Up @@ -350,6 +350,7 @@ func (hs *httpSourceHandler) save(ctx context.Context, resp *http.Response, s se
dgst = digest.NewDigest(digest.SHA256, h)

if respETag := resp.Header.Get("ETag"); respETag != "" {
respETag = etagValue(respETag)
if err := md.setETag(respETag); err != nil {
return nil, "", err
}
Expand Down Expand Up @@ -471,3 +472,8 @@ func (md cacheRefMetadata) getHTTPModTime() string {
func (md cacheRefMetadata) setHTTPModTime(s string) error {
return md.SetString(keyModTime, s, "")
}

func etagValue(v string) string {
// remove weak for direct comparison
return strings.TrimPrefix(v, "W/")
}