-
Notifications
You must be signed in to change notification settings - Fork 25k
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
RestController should not consume request content #44902
RestController should not consume request content #44902
Conversation
Pinging @elastic/es-core-infra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()
.
@rjernst Thanks for your feedback. I applied your suggestion, can you please have another look? |
@elasticmachine update branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@elasticmachine run elasticsearch-ci/bwc |
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. |
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.
…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
* 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)
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 <[email protected]>
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 theRestRequest
object and itscontentConsumed
attribute, which is set totrue
when 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
RestController
always 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.testBodyRejection
so 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.