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

Do not write manifests on HEAD requests #4286

Merged

Conversation

jaimem88
Copy link
Contributor

@jaimem88 jaimem88 commented Feb 28, 2024

The GetManifest handler is used for both HEAD and GET requests. For HEAD requests, the handler also calls w.Write() on the response writer.

This is not needed as HEAD requests should not include a response body. Most clients will actually just ignore the body, for example curl does this and simply skips it.

This PR adds a check to the GetManifest handler to return early when the request method is a HEAD. This would prevent wasting resources writing to the response writer.

The ServeBlob method of the blobServer uses the standard library http.ServeContent which internally has a check to only copy the result if the request method is not HEAD. So this change will follow the same approach as the blobs handler.

The change has also been recently merged to GitLab's Container Registry via https://gitlab.com/gitlab-org/container-registry/-/merge_requests/1585.

@jaimem88 jaimem88 force-pushed the fix-do-not-write-manifest-head-requests branch 2 times, most recently from 6206998 to 2e0bdf3 Compare February 28, 2024 05:12
@jaimem88
Copy link
Contributor Author

@joaodrp can you please have a look here as well?

@wy65701436
Copy link
Collaborator

according the distribution spec outlined in the heading and manifest, it makes sense to me.

A HEAD request to an existing blob or manifest URL MUST return 200 OK. A successful response SHOULD contain the digest of the uploaded blob in the header Docker-Content-Digest. A successful response SHOULD contain the size in bytes of the uploaded blob in the header Content-Length.

If the blob or manifest is not found in the registry, the response code MUST be 404 Not Found.

@wy65701436
Copy link
Collaborator

@jaimem88 please help to fix the CI failure.

Copy link
Collaborator

@joaodrp joaodrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Collaborator

@Jamstah Jamstah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM.

@thaJeztah
Copy link
Member

I recalled there was some discussion about HEAD requests, but that was not about body. And looking back at my comments there, the http RFC even marks it as "MUST NOT send a body"; #3691 (comment)

@thaJeztah
Copy link
Member

changes LGTM, but could you squash the commits? Looks like the second one is fixing an issue that was introduced in the first commit, so we don't need to preserve that fix up in history

Signed-off-by: Jaime Martinez <jmartinez@gitlab.com>
@jaimem88 jaimem88 force-pushed the fix-do-not-write-manifest-head-requests branch from 5cb0f8d to 2763ba1 Compare February 29, 2024 00:16
Copy link
Collaborator

@wy65701436 wy65701436 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@joaodrp joaodrp merged commit 6a568c1 into distribution:main Feb 29, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants