Add apply method to WebClient.Builder

This commit introduces an apply method to `WebClient.Builder`, allowing
users to make multiple changes to the builder in one consumer.

Issue: SPR-15743
This commit is contained in:
Arjen Poutsma
2017-07-12 11:05:03 +02:00
parent 9ac71afbda
commit d6c102d1b8
3 changed files with 32 additions and 5 deletions

View File

@@ -157,6 +157,19 @@ public class DefaultWebClientTests {
client.get().uri("/path").attribute("foo", "bar").exchange();
}
@Test
public void apply() {
WebClient client = builder()
.apply(builder -> builder.defaultHeader("Accept", "application/json").defaultCookie("id", "123"))
.build();
client.get().uri("/path").exchange();
ClientRequest request = verifyExchange();
assertEquals("application/json", request.headers().getFirst("Accept"));
assertEquals("123", request.cookies().getFirst("id"));
verifyNoMoreInteractions(this.exchangeFunction);
}
private WebClient.Builder builder() {