WebClient uri method with uriTemplate and UriBuilder
See gh-22705
This commit is contained in:
committed by
Rossen Stoyanchev
parent
ed70978071
commit
9976783639
@@ -184,6 +184,12 @@ class DefaultWebClient implements WebClient {
|
||||
return uri(uriBuilderFactory.expand(uriTemplate, uriVariables));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBodySpec uri(String uriTemplate, Function<UriBuilder, URI> uriFunction) {
|
||||
attribute(URI_TEMPLATE_ATTRIBUTE, uriTemplate);
|
||||
return uri(uriFunction.apply(uriBuilderFactory.uriString(uriTemplate)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBodySpec uri(Function<UriBuilder, URI> uriFunction) {
|
||||
return uri(uriFunction.apply(uriBuilderFactory.builder()));
|
||||
|
||||
@@ -348,9 +348,16 @@ public interface WebClient {
|
||||
*/
|
||||
S uri(String uri, Map<String, ?> uriVariables);
|
||||
|
||||
/**
|
||||
* Build the URI for the request using the {@link UriBuilderFactory}
|
||||
* configured for this client and initialized with the specified <code>uri</code>.
|
||||
*/
|
||||
S uri(String uri, Function<UriBuilder, URI> uriFunction);
|
||||
|
||||
/**
|
||||
* Build the URI for the request using the {@link UriBuilderFactory}
|
||||
* configured for this client.
|
||||
* @see #uri(String, Function)
|
||||
*/
|
||||
S uri(Function<UriBuilder, URI> uriFunction);
|
||||
}
|
||||
|
||||
@@ -84,6 +84,18 @@ public class DefaultWebClientTests {
|
||||
assertEquals("/base/path?q=12", request.url().toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void uriBuilderWithUriTemplate() {
|
||||
this.builder.build().get()
|
||||
.uri("/path/{id}", builder -> builder.queryParam("q", "12").build("identifier"))
|
||||
.exchange().block(Duration.ofSeconds(10));
|
||||
|
||||
ClientRequest request = verifyAndGetRequest();
|
||||
assertEquals("/base/path/identifier?q=12", request.url().toString());
|
||||
assertEquals("/path/{id}", request.attribute(WebClient.class.getName() + ".uriTemplate").<String>get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriBuilderWithPathOverride() {
|
||||
this.builder.build().get()
|
||||
|
||||
Reference in New Issue
Block a user