Merge pull request #22705 from jhaeyaert/22371

This commit is contained in:
Rossen Stoyanchev 2019-04-04 17:15:18 -04:00
commit 279508a0f0
3 changed files with 27 additions and 3 deletions

View File

@ -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()));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -349,8 +349,15 @@ public interface WebClient {
S uri(String uri, Map<String, ?> uriVariables);
/**
* Build the URI for the request using the {@link UriBuilderFactory}
* configured for this client.
* Specify the URI starting with a URI template and finishing off with a
* {@link UriBuilder} created from the template.
* @since 5.2
*/
S uri(String uri, Function<UriBuilder, URI> uriFunction);
/**
* Specify the URI by through a {@link UriBuilder}.
* @see #uri(String, Function)
*/
S uri(Function<UriBuilder, URI> uriFunction);
}

View File

@ -84,6 +84,17 @@ public class DefaultWebClientTests {
assertEquals("/base/path?q=12", request.url().toString());
}
@Test // gh-22705
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").get());
}
@Test
public void uriBuilderWithPathOverride() {
this.builder.build().get()