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

Allow non destructive reads of request body #426

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

willmostly
Copy link
Contributor

@willmostly willmostly commented Jul 30, 2024

Description

HttpServeletRequest only supports destructive reads of a request's body. This change ensures different components can access the request body without interfering with one another.

Fixes #427
Fixes #428

Additional context and related issues

The body of a request is consumed by the ServeletHandlers that supply the body argument to RouteToBackendResource.postHandler. It is necessary to re-associate the body with the request so it can be used by downstream query id extraction logic and routing rules.

Release notes

(x ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

@cla-bot cla-bot bot added the cla-signed label Jul 30, 2024
Comment on lines +67 to +68
String remoteUri = routingTargetHandler.getRoutingDestination(multiReadHttpServletRequest);
proxyRequestHandler.postRequest(body, multiReadHttpServletRequest, asyncResponse, URI.create(remoteUri));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this apply only to POST and not to others GET, DELETE?
Would it not be safer to use MultiReadHttpServletRequest instead of HttpServletRequest in all cases?
including RoutingGroup codes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the GETs and DELETEs won't have bodies, so getReader and getInputStream will be null either way

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, hmm.. how about using one type just for unifcation for all cases? even if it doesn't have body?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that is what @oneonestar was suggesting with the plan to replace HttpServeletRequest with a dedicated class like TrinoRequestContext. This is the way to go, but would broaden the scope of this PR by quite a bit. So for now I think we can get by with HttpServletRequest, using the MultiRead implementation when there is a body

Copy link
Member

@Chaho12 Chaho12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Btw would this change not be applied to TrinoQueryProperties too?

Comment on lines +67 to +68
String remoteUri = routingTargetHandler.getRoutingDestination(multiReadHttpServletRequest);
proxyRequestHandler.postRequest(body, multiReadHttpServletRequest, asyncResponse, URI.create(remoteUri));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, hmm.. how about using one type just for unifcation for all cases? even if it doesn't have body?

@willmostly
Copy link
Contributor Author

LGTM. Btw would this change not be applied to TrinoQueryProperties too?

TrinoQueryProperties is downstream of postHandler, so it will get this change

@willmostly willmostly merged commit e6b45cf into trinodb:main Aug 1, 2024
2 checks passed
@github-actions github-actions bot added this to the 11 milestone Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

requestAnalyzer is non functional system.runtime.kill_query queries not routed to correct cluster
2 participants