From 13acc5828603177ab9b0cf5b871c65dbbdaa6ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Rigault?= Date: Wed, 10 Apr 2024 08:31:36 +0200 Subject: [PATCH] clairctl: warn when range requests are not honored MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As discussed in https://github.com/quay/clair/issues/2029 the manifest generation is efficient only when HTTP "Range: bytes=0-0" header is well supported by the server. If not, the server might return the full layer, making the manifest generation very expensive. We warn the user in case their HTTP server does not support HTTP range requests. Signed-off-by: François Rigault --- cmd/clairctl/manifest.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/clairctl/manifest.go b/cmd/clairctl/manifest.go index ce9ceedbf1..cafc3380f4 100644 --- a/cmd/clairctl/manifest.go +++ b/cmd/clairctl/manifest.go @@ -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")