RestController should not consume request content#44902
Merged
tlrx merged 4 commits intoelastic:masterfrom Jul 28, 2019
Merged
Conversation
Collaborator
|
Pinging @elastic/es-core-infra |
rjernst
reviewed
Jul 26, 2019
Member
rjernst
left a comment
There was a problem hiding this comment.
Instead of using this internal variant of content that takes in whether or not to mark the content as consumed, can we add a contentLength() method that will internally check this? I think then content(boolean) can be removed as the only user of content(false) is the check to content length in hasContent().
Member
Author
|
@rjernst Thanks for your feedback. I applied your suggestion, can you please have another look? |
Member
Author
|
@elasticmachine update branch |
Member
Author
|
@elasticmachine run elasticsearch-ci/bwc |
Member
Author
|
Thanks @rjernst ! Because this fix might break existing APIs, I don't think it should be backported to 7.x. Thus I'm removing the 7.3/7.4 labels. |
jkakavas
pushed a commit
that referenced
this pull request
Jul 31, 2019
The change #37504 modifies the BaseRestHandler to make it reject all requests that have an unconsumed body. The notion of consumed or unconsumed body is carried by the RestRequest object and its contentConsumed attribute, which is set to true when the content() or content(true) methods are used. In our REST layer, we usually expect the RestHandlers to consume the request content when needed, but it appears that the RestController always consumes the content upfront. This commit changes the content() method used by the RestController so that it does not mark the content as consumed.
Mpdreamz
added a commit
to elastic/elasticsearch-net
that referenced
this pull request
Aug 6, 2019
…d any body if no body is documented we relied on serializing empty bodies but the server is now (rightfully) much stricter here. elastic/elasticsearch#44902
Mpdreamz
added a commit
to elastic/elasticsearch-net
that referenced
this pull request
Aug 7, 2019
* Update abstractions to version that prints JAVA_HOME just before starting elasticsearch and forces it on the Process instance * update abstractions * SkipVersion SNAPSHOT failing tests for now * Make sure we take `body: null` into account from the spec and not send any body if no body is documented we relied on serializing empty bodies but the server is now (rightfully) much stricter here. elastic/elasticsearch#44902 * Run codegen for SupportsBody * Un skipped test failures due to sending bodies where non was expected * Fix root node info tests when running against snapshots * Audit trail test assumed timespan is never TimeSpan.Zero but of course can be (#3989) (cherry picked from commit 79a71ac)
jaymode
added a commit
that referenced
this pull request
Dec 14, 2020
The change #37504 modifies the BaseRestHandler to make it reject all requests that have an unconsumed body. The notion of consumed or unconsumed body is carried by the RestRequest object and its contentConsumed attribute, which is set to true when the content() or content(true) methods are used. In our REST layer, we usually expect the RestHandlers to consume the request content when needed, but it appears that the RestController always consumes the content upfront. This commit changes the content() method used by the RestController so that it does not mark the content as consumed. Backport of #44902 Closes #65242 Co-authored-by: Tanguy Leroux <tlrx.dev@gmail.com>
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.
The change #37504 modifies the
BaseRestHandlerto make it reject all requests that have an unconsumed body. The notion of consumed or unconsumed body is carried by theRestRequestobject and itscontentConsumedattribute, which is set totruewhen thecontent()orcontent(true)methods are used.In our REST layer, we usually expect the RestHandlers to consume the request content when needed, but it appears that the
RestControlleralways consumes the content upfront:final int contentLength = request.hasContent() ? request.content().length() : 0;making the check in BaseRestHandler useless:
This pull request changes the
content()method used by the RestController tocontent(false)so that it does not mark the content as consumed. It also adds a test for this and changes theForceMergeActionTests.testBodyRejectionso that it uses the usualdispactchRequest()execution path (as a normal request would do).Finally, it fixes some Rollup request objects that were generating a request body for APIs that do not require a body.