Better support for overriding base URI in WebClient

The base URI is ignored for requests that include a host.

WebClient exposes UriBuilder (rather than UriBuilderFactory) for
per-request URI building based on the base URI. That provides
full control to add or replace components of the base URI.
This commit is contained in:
Rossen Stoyanchev
2017-02-02 17:09:53 -05:00
parent 82a34f4b24
commit 1466c82f53
6 changed files with 93 additions and 36 deletions

View File

@@ -64,6 +64,26 @@ public class DefaultWebClientTests {
assertEquals(Collections.emptyMap(), request.cookies());
}
@Test
public void uriBuilder() throws Exception {
WebClient client = builder().build();
client.get().uri(builder -> builder.path("/path").queryParam("q", "12").build()).exchange();
ClientRequest<?> request = verifyExchange();
assertEquals("/base/path?q=12", request.url().toString());
verifyNoMoreInteractions(this.exchangeFunction);
}
@Test
public void uriBuilderWithPathOverride() throws Exception {
WebClient client = builder().build();
client.get().uri(builder -> builder.replacePath("/path").build()).exchange();
ClientRequest<?> request = verifyExchange();
assertEquals("/path", request.url().toString());
verifyNoMoreInteractions(this.exchangeFunction);
}
@Test
public void requestHeaderAndCookie() throws Exception {
WebClient client = builder().build();