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

Don't set content-length header for HEAD requests with empty body #1067

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

waseigo
Copy link

@waseigo waseigo commented Jun 24, 2024

defp put_content_length_header(headers, "", :head), do: headers

This extra function clause in lib/ex_aws/operation/s3.ex prevents the content-length header from being added to the headers of a HEAD request with an empty body (in which case the body of the request is an empty string and the value of that header would be "0").

This is compliant with Amazon's specification of the HeadObject API endpoint, as it doesn't specify the content-length header as part of the URI Request Parameters.

As an added benefit, this makes ExAws and ExAws.S3 work with Garage. Unlike Minio, Garage doesn't gracefully handle the extraneous presence of the {"content-length", "0"} header in the request headers of the HeadObject call.

[x] Run mix format using a recent version of Elixir
[x] Run mix dialyzer to make sure the typing is correct
[x] Run mix test to ensure no tests have broken (also please make sure you've added tests for your particular change, where appropriate) (no new tests added)

This extra function clause prevents the `content-length` (equals 0)
header from being added to the headers of a `HEAD` request with an empty
body. This is compliant with [Amazon's specification of the HeadObject
API endpoint] that doesn't specify the `content-length` header as part
of the URI Request Parameters. As a benefit, this makes ExAws and
ExAws.S3 work with [Garage](https://garagehq.deuxfleurs.fr/), which,
unlike [Minio](https://min.io), doesn't gracefully handle the extraneous
presence of the `{"content-length", "0"}` header in the request headers
of the HeadObject call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant