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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user