You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Registry unnecessarily redirects blob HEAD requests to storage URL #3691
When the "redirect" option is set to true, it applies to both HEAD and GET requests for blobs. The use case for GETs makes sense - this avoids the registry needing to proxy potentially large blobs from the storage backend to the client. But in the case of HEAD requests, the registry has already done a Stat, and could simply return that information to the client, but instead is issuing a redirect which can add considerable latency.
Am I missing anything that justifies this behavior? Would you be open to a PR to change ServeBlob to avoid redirecting HEAD requests?
The HEAD method is identical to GET except that the server MUST NOT send content in the response. HEAD is used to obtain metadata about the selected representation without transferring its representation data, often for the sake of testing hypertext links or finding recent modifications.
The server SHOULD send the same header fields in response to a HEAD request as it would have sent if the request method had been GET. However, a server MAY omit header fields for which a value is determined only while generating the content. For example, some servers buffer a dynamic response to GET until a minimum amount of data is generated so that they can more efficiently delimit small responses or make late decisions with regard to content selection. Such a response to GET might contain Content-Length and Vary fields, for example, that are not generated within a HEAD response. These minor inconsistencies are considered preferable to generating and discarding the content for a HEAD request, since HEAD is usually requested for the sake of efficiency.
I guess this part may be relevant here;
However, a server MAY omit header fields for which a value is determined only while generating the content.
Performing the Stat would fall within that bit, but I guess it still needs to do the Stat in order to get the redirect location?
I don't think it would violate the RFC for the registry to generate its own response to a HEAD using the stat information it already has. In fact, the RFC seems to encourage this kind of optimization:
These minor inconsistencies are considered preferable to generating and discarding the content for a HEAD request, since HEAD is usually requested for the sake of efficiency.
Thinking a bit further; so, in your case, there's HEAD request, but the client sees the redirect, so follows it?
Wondering if that's the part to look into; basically; if the HEAD has the headers it need, it wouldn't have to follow the redirect and do another request. I think that would still comply to the RFC if we do the same for both GET and HEAD
The cache headers should probably be omitted though in that case, as (IIUC) the redirect-to URL would be an ephemeral URL, so result should not be cached?
From the above, it feels like 1. is fine, but 2. may not be.
However, I think clients should be allowed to ignore a Location header (don't follow redirects), so in case the response contains the headers they need, they can ignore the Location header and be done. Clients that don't have that logic would continue to follow the redirect.
However, I think clients should be allowed to ignore a Location header (don't follow redirects), so in case the response contains the headers they need, they can ignore the Location header and be done. Clients that don't have that logic would continue to follow the redirect.
I'm pretty sure existing clients do not have htis logic. Anything written in Go (such as Docker) will follow redirects automatically by default, unless this is explicitly disabled. I do not see the distribution client disabling redirect following:
req, err:=http.NewRequestWithContext(ctx, "HEAD", u, nil)
iferr!=nil {
return distribution.Descriptor{}, err
}
resp, err:=bs.client.Do(req)
Anyway, I think it would make a lot of sense to at least provide an opt-in setting for people who prefer efficiency and cost savings over strict RFC compliance.
Activity
aaronlehmann commentedon Jul 20, 2022
@milosgajdos: Any thoughts on this?
thaJeztah commentedon Jul 27, 2022
From your description, the current behavior seems to comply with the HTTP specs; from RFC9110
I guess this part may be relevant here;
Performing the
Statwould fall within that bit, but I guess it still needs to do the Stat in order to get the redirect location?aaronlehmann commentedon Jul 27, 2022
I don't think it would violate the RFC for the registry to generate its own response to a
HEADusing the stat information it already has. In fact, the RFC seems to encourage this kind of optimization:thaJeztah commentedon Jul 27, 2022
Thinking a bit further; so, in your case, there's
HEADrequest, but the client sees theredirect, so follows it?Wondering if that's the part to look into; basically; if the
HEADhas the headers it need, it wouldn't have to follow the redirect and do another request. I think that would still comply to the RFC if we do the same for bothGETandHEADThe cache headers should probably be omitted though in that case, as (IIUC) the redirect-to URL would be an ephemeral URL, so result should not be cached?
distribution/registry/storage/blobserver.go
Lines 59 to 60 in 8857a19
thaJeztah commentedon Jul 27, 2022
Right, so I think there's two bits here;
Add the extra headers
distribution/registry/storage/blobserver.go
Lines 62 to 65 in 8857a19
Remove the
LocationheaderFrom the above, it feels like
1.is fine, but2.may not be.However, I think clients should be allowed to ignore a
Locationheader (don't follow redirects), so in case the response contains the headers they need, they can ignore theLocationheader and be done. Clients that don't have that logic would continue to follow the redirect.aaronlehmann commentedon Jul 27, 2022
I'm pretty sure existing clients do not have htis logic. Anything written in Go (such as Docker) will follow redirects automatically by default, unless this is explicitly disabled. I do not see the
distributionclient disabling redirect following:distribution/registry/client/repository.go
Lines 876 to 880 in 8857a19
Anyway, I think it would make a lot of sense to at least provide an opt-in setting for people who prefer efficiency and cost savings over strict RFC compliance.