Fix ExAws.Request.Req: don't rewrite bodyless GETs to POST - #1251
Open
gernotkogler wants to merge 2 commits into
Open
Fix ExAws.Request.Req: don't rewrite bodyless GETs to POST#1251gernotkogler wants to merge 2 commits into
gernotkogler wants to merge 2 commits into
Conversation
Req rewrites a GET into a POST when a non-nil request body is set. ExAws represents a bodyless request with "" (e.g. an S3 GET), so the documented Req adapter turned every such GET into a POST and servers replied 405. Normalise an empty body to nil so the method is preserved.
|
This kind of addresses #1246, but it would be even better if it fixed the existing Req adapter already in ExAws: ex_aws/lib/ex_aws/request/req.ex Line 19 in 48785c6 |
Req 0.7 rewrites a GET into a POST when a non-nil request body is set. ExAws calls the adapter with "" for bodyless requests, so every GET made through ExAws.Request.Req went out as a POST; SigV4 is signed over the GET, so the server rejects it with SignatureDoesNotMatch (issue ex-aws#1246). Normalise an empty body to nil so the method is preserved, and add a regression test asserting a bodyless GET reaches the server as a GET.
Author
|
Good call — I hadn't spotted the shipped |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1246.
Req 0.7 automatically converts a GET into a POST when a non-nil request body is set. ExAws calls its HTTP client with
""for bodyless requests (every S3 GET is built withbody: data[:body] || ""), and"" != nil, so every GET made throughExAws.Request.Reqgoes out as a POST. Because SigV4 is signed over the original GET, the server rejects it withSignatureDoesNotMatch(or, for non-signed backends, 405).In Req's model "no body" is
nil, not"", so the adapter just needs to translate ExAws's convention:Changes:
ExAws.Request.Reqadapter (normalise""→nil)POSTunder req 0.7.2 without the fix, passing with it)ExAws.Request.HttpClientmoduledocOnly
:getis affected by Req's rewrite, so HEAD/PUT/POST/DELETE are unchanged.