-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
WebClient's UriBuilder option should encode path parameters passed into build [SPR-17465] #21997
Comments
Rossen Stoyanchev commented Indeed there is an issue. The explanation is made a little more complicated by the fact that in 5.1, the encoding mode for After the change to encoding mode For more background on those options see the reference docs. |
Rossen Stoyanchev commented Benjamin Conlan I updated my previous comment to say 5.1 (instead of 5.0.8), as it should have been. For 5.0.x the example you gave is expected behavior I'm afraid. You would have to use For 5.1.x after the fix in 5.1.3 the example should just work since in 5.1.x the default encoding mode is |
I'm upgrading from
now returns When using
but also this won't work anymore > @rstoyanchev what should be the approach from |
@marceloverdijk, in 5.1.x TEMPLATE_AND_VALUES encoding applies by default, which is why pre-encoding any part of the template leads to double encoding. In 5.1.2 there was a bug that prevented this. This encoding mode however applies full encoding to URI variables so you can do: String query = "{foo}";
client.get().uri(uriBuilder -> uriBuilder.path("/graphql")
.queryParam("query", "{query}")
.build(query))
.accept(MediaType.APPLICATION_JSON_UTF8)
.exchange()
.expectStatus().isOk(); |
Thx @rstoyanchev that worked! |
@rstoyanchev this works for fixed parameters, but how would you suggest handling dynamic query parameters. Having to create an array to hand over to Here is a short example: List<String> rels = ... // list of strings also containing special chars
webClient.get().uri(baseUri, uriBuilder -> {
uriBuilder.queryParam("email", "{email}");
rels.forEach(rel -> uriBuilder.queryParam(REL_PARAM, rel)); // how should we handle this?
return uriBuilder.build(email);
} |
UriUtils#encodeQueryParams perhaps, assuming the rest of the URI template is already encoded. |
Benjamin Conlan opened SPR-17465 and commented
When using the reactive web WebClient's uribuilder building a Uri path value doesn't get encoded as expected:
(Excuse code here... Composed from phone)
Behaves differently to:
I would expect the url path segment in the 1st case to also be encoded.
Affects: 5.0.8
Issue Links:
Referenced from: commits 2405161, e4c84ec
Backported to: 5.0.11
The text was updated successfully, but these errors were encountered: