Affects: <spring-webflux 5.1.8.RELEASE>
Please see a demo .
public static void main(String args[]){
DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory();
uriBuilderFactory.setEncodingMode(EncodingMode.NONE);
WebClient webClient = WebClient.builder().uriBuilderFactory(uriBuilderFactory)
.baseUrl("http://localhots:9090").build();
webClient.get().uri("/api/v1/query").retrieve().bodyToMono(String.class).block();
}
Maybe you already know what I mean.
I want a webClient implementation that does not perform url encoding and decoding and has a baseurl. But unfortunately my code above seems to be able to meet my needs, but in fact baseurl does not take effect.
I looked through the source code,the root cause is found in the following code.
private UriBuilderFactory initUriBuilderFactory() {
if (this.uriBuilderFactory != null) {
return this.uriBuilderFactory;
}
DefaultUriBuilderFactory factory = this.baseUrl != null ?
new DefaultUriBuilderFactory(this.baseUrl) : new DefaultUriBuilderFactory();
factory.setDefaultUriVariables(this.defaultUriVariables);
return factory;
}
If uriBuilderFactory is set, baseurl will be ignored.I looked at the specific implementation of DefaultUriBuilderFactory again,At this point I understand that the correct way should be to set the baseurl through the constructor of DefaultUriBuilderFactory.
I think this kind of API design that If uriBuilderFactory is set, baseurl will be ignored will cause some confusion.I wonder if you think so.Is it possible to eliminate this confusion by improving the DefaultUriBuilderFactory and related code.
Thank you for reading and sincerely look forward to your reply.
Affects: <spring-webflux 5.1.8.RELEASE>
Please see a demo .
Maybe you already know what I mean.
I want a webClient implementation that does not perform url encoding and decoding and has a baseurl. But unfortunately my code above seems to be able to meet my needs, but in fact baseurl does not take effect.
I looked through the source code,the root cause is found in the following code.
If
uriBuilderFactoryis set,baseurlwill be ignored.I looked at the specific implementation ofDefaultUriBuilderFactoryagain,At this point I understand that the correct way should be to set thebaseurlthrough the constructor ofDefaultUriBuilderFactory.I think this kind of API design that If
uriBuilderFactoryis set,baseurlwill be ignored will cause some confusion.I wonder if you think so.Is it possible to eliminate this confusion by improving theDefaultUriBuilderFactoryand related code.Thank you for reading and sincerely look forward to your reply.