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

backport: clairctl: warn when range requests are not honored #2044

Merged
merged 1 commit into from
Apr 29, 2024
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: 10 additions & 0 deletions cmd/clairctl/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,22 @@ func Inspect(ctx context.Context, r string) (*claircore.Manifest, error) {
if err != nil {
return nil, err
}
// The request is needed to follow any redirection chain that the server sends to a client,
// but the actual body is not needed when generating a manifest.
// The Range HTTP header allows us to send the request and get a response mostly for free.
req.Header.Add("Range", "bytes=0-0")
res, err := c.Do(req)
if err != nil {
return nil, err
}
res.Body.Close()
if res.StatusCode != http.StatusPartialContent {
zlog.Warn(ctx).
Int("statuscode", res.StatusCode).
Int("len", int(res.ContentLength)).
Str("url", u.String()).
Msg("server might not support requests with Range HTTP header")
}

res.Request.Header.Del("User-Agent")
res.Request.Header.Del("Range")
Expand Down
Loading