Fix ApacheHttpClient's handling of request bodies on DELETE, GET, HEAD & OPTIONS requests #5743
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.
This is a rework of #5704 that was reverted.
Have modified logic to only use the entity enclosing request type on
DELETE
,GET
,HEAD
&OPTIONS
when a content stream provider is present, ensuring the previous behavior of no Content-Length header being sent is retained.Summary copied from previous PR:
Motivation and Context
Though providing request bodies on these HTTP methods is uncommon, it is not disallowed by the spec, and is used in certain Elasticsearch/OpenSearch APIs. Authenticating with Amazon OpenSearch Service can be done via SigV4 and we re-use the SDK's signing logic to provide that in https://github.com/opensearch-project/opensearch-java.
We've received multiple bug reports of users having trouble making certain requests using the
ApacheHttpClient
(opensearch-project/opensearch-java#712, opensearch-project/opensearch-java#521), where the client itself doesn't complain or error but silently drops the request body resulting in a mismatched signature on the server.The Netty & CRT
Sdk(Async)HttpClient
implementations correctly send the request body for all methods, URL Connection does as well with the exception ofGET
which is hardcoded to swap toPOST
(and doesn't supportPATCH
at all).As such I think it is not harmful to bring the Apache implementation in line with the other client implementations.
Modifications
Generalize the Apache HTTP request factory implementation to attach the request body entity on all HTTP methods.
This matches the original implementations of the separate method classes:
Testing
Added unit tests
Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License