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 to skip parsing the request's url into URI #10178

Merged
merged 4 commits into from
Dec 5, 2023
Merged

Allow to skip parsing the request's url into URI #10178

merged 4 commits into from
Dec 5, 2023

Conversation

dstepanov
Copy link
Contributor

Based on #10177

@@ -200,34 +197,6 @@ public NettyHttpRequest(io.netty.handler.codec.http.HttpRequest nettyRequest,
this.channelHandlerContext = ctx;
this.headers = new NettyHttpHeaders(nettyRequest.headers(), conversionService);
this.body = ByteBody.of(nettyRequest);
this.contentLength = headers.contentLength().orElse(-1);
Copy link
Member

Choose a reason for hiding this comment

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

are these three actually worthwhile? i would guess they are always accessed anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After thinking about it more, I will move the caching to headers and avoid nullifying it. Keep it this way for now. Routing should avoid checking the headers in cases when it will always match for any content-type/accepts.

Copy link
Member

Choose a reason for hiding this comment

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

i think always matching is rare, it's not the default

@@ -59,8 +59,6 @@ final class NettyRequestLifecycle extends RequestLifecycle {
super(rib.routeExecutor);
this.rib = rib;
this.outboundAccess = outboundAccess;

multipartEnabled(rib.multipartEnabled);
Copy link
Member

Choose a reason for hiding this comment

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

what is this replaced by

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Configuration is extracted from the route executor in RequestLifecycle.

Copy link
Member

Choose a reason for hiding this comment

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

did you test this with servlet? i think this check was only present in RoutingInBoundHandler which is why i only added it to NettyRequestLifecycle and not the RequestLifecycle

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 check is coming from the shared config so I expect it's valid in the servlet

http/src/main/java/io/micronaut/http/HttpRequest.java Outdated Show resolved Hide resolved
@dstepanov
Copy link
Contributor Author

@yawkat I'm trying to remove the new getUrl method to avoid creating an invalidated method, but if I revert HateoasErrorResponseProcessor I get a memory leak detected in FuzzyInputSpec. Can you please check? I think we have a leak when the error is thrown from ErrorResponseProcessor

@yawkat
Copy link
Member

yawkat commented Dec 4, 2023

ok i'll do my best, still on the train though so it might take a while :)

@dstepanov
Copy link
Contributor Author

Hopefully, it's not a Czech train and Wi-Fi :D

@yawkat
Copy link
Member

yawkat commented Dec 4, 2023

worse. german train wifi

@dstepanov
Copy link
Contributor Author

I added a check to prevent an exception from propagating and removed all getUrl methods.

@yawkat
Copy link
Member

yawkat commented Dec 4, 2023

the leak happens because RequestHandler.accept throws an exception, which it shouldnt. but PipeliningServerHandler needs to handle that better. so i will make a note to improve that

@yawkat
Copy link
Member

yawkat commented Dec 4, 2023

what did the force push change, just rebase? i dont want to review everything again

Base automatically changed from filterr3 to 4.3.x December 4, 2023 15:57
@dstepanov dstepanov marked this pull request as ready for review December 4, 2023 18:25
@dstepanov
Copy link
Contributor Author

Had to rewrite it a bit, moved some of the cached fields into the headers implementation.

@dstepanov dstepanov requested a review from yawkat December 5, 2023 10:35
return this;
}

private void onModify(CharSequence header) {
if (contentType != null && header.equals(HttpHeaders.CONTENT_TYPE)) {
Copy link
Member

Choose a reason for hiding this comment

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

can't use equals here, it's CharSequence. Is this called on the hot path? maybe it's fine to just unset all the caches and be done with it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, looks like the the modifications are mostly for the response anyway

Copy link

sonarqubecloud bot commented Dec 5, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 9 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

88.9% 88.9% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@dstepanov dstepanov merged commit 8c85ca2 into 4.3.x Dec 5, 2023
14 of 15 checks passed
@dstepanov dstepanov deleted the filterr4 branch December 5, 2023 13:18

return runWithFilters(request, (filteredRequest, propagatedContext) -> executeRoute(filteredRequest, propagatedContext, routeMatch));
return runWithFilters(request, (filteredRequest, propagatedContext) -> {
if (validateUrl) {
Copy link
Member

Choose a reason for hiding this comment

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

@dstepanov why does this happen inside the filter execution? i think it should go before. if it's placed here, it's possible a filter will see and work with an invalid path, which might be a security issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can move it somewere else, the filter cannot see the invalid path because it will throw an exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants