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

Use overloaded method with java.net.URI of Reactor Netty HttpClient #29954

Closed

Conversation

yuzawa-san
Copy link
Contributor

@yuzawa-san yuzawa-san commented Feb 10, 2023

I was doing some flame graph analysis and found that despite passing a URI into the WebClient, a string version of the URI was being passed into the reactor-netty library where it was parsed again in the UriEndpointFactory: https://github.com/reactor/reactor-netty/blob/dfb1e18551bd51a6cc406acdb923b66c9d7bbada/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConnect.java#L497-L513

Later, the URI is constructed again further inside that library https://github.com/reactor/reactor-netty/blob/dfb1e18551bd51a6cc406acdb923b66c9d7bbada/reactor-netty-http/src/main/java/reactor/netty/http/HttpOperations.java#L429 I may take a stab at cleaning up that in reactor/reactor-netty#829 once the URI is passed from spring. Ideally, I could make the URI passed into spring live all the way thru the lifecycle.

NOTE: this assumes a full URI is present like http://example.com/blah not /blah. When I hit breakpoints here, it appeared that they were all full URI's.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 10, 2023
@rstoyanchev rstoyanchev self-assigned this Feb 14, 2023
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 14, 2023
@rstoyanchev rstoyanchev added this to the 6.0.5 milestone Feb 14, 2023
@rstoyanchev rstoyanchev changed the title Send URI to reactor-netty HTTP client Use overloaded method with java.net.URI of Reactor Netty HttpClient Feb 14, 2023
@rstoyanchev
Copy link
Contributor

Thanks for spotting this.

@yuzawa-san
Copy link
Contributor Author

yuzawa-san commented Feb 14, 2023

I recently found that is theoretically possible to have spring generate a non-absolute URI but that would only work if the user was customizing the reactor-netty httpclient to also have a baseUrl. So it is possible, but rare and contradictory to the advice given in the existing javadoc.

// these will call http://localhost/test but will now break
WebClient webClient = WebClient.create();
webClient.get().uri("/test").retrieve().toBodilessEntity().block();
webClient.get().uri(URI.create("/test")).retrieve().toBodilessEntity().block();

this was caused by
https://github.com/reactor/reactor-netty/blob/dd366557b172132238bdecc08d7e4c80ca186543/reactor-netty-http/src/main/java/reactor/netty/http/client/UriEndpointFactory.java#L48-L50
but would be prevent now by
https://github.com/reactor/reactor-netty/blob/dd366557b172132238bdecc08d7e4c80ca186543/reactor-netty-http/src/main/java/reactor/netty/http/client/UriEndpointFactory.java#L74-L76

rstoyanchev pushed a commit that referenced this pull request Feb 14, 2023
mdeinum pushed a commit to mdeinum/spring-framework that referenced this pull request Jun 29, 2023
mdeinum pushed a commit to mdeinum/spring-framework that referenced this pull request Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants