Replace WebClient.filter with Builder.filter

This commit replaces the WebClient.filter method with
WebClient.Builder.filter. The reason for this change is that filters
added via WebClient.filter would be applied in the opposite order of
their declaration, due to the compositional nature of the method,
combined with the immutable nature of the WebClient.
WebClient.Builder.filter does keep the order of the filters, as
registered.

Furthermore, this commit introduces a WebClient.mutate() method,
returning a WebClient.Builder. This method allow to add/remove filters
and other defaults from a given WebClient.

Issue: SPR-15657

Add WebClient.Builder.addFilter

Add Consumer-based headers and cookies methods to builders.

Add WebClient.mutate
This commit is contained in:
Arjen Poutsma
2017-06-19 11:40:10 +02:00
parent 52148a10b7
commit 4a0597d612
9 changed files with 325 additions and 81 deletions

View File

@@ -59,8 +59,14 @@ public class ExchangeMutatorWebFilterTests {
@Test
public void perRequestMutators() throws Exception {
this.webTestClient
this.webTestClient = WebTestClient.bindToController(new TestController())
.webFilter(this.exchangeMutator)
.configureClient()
.filter(this.exchangeMutator.perClient(userIdentity("Giovanni")))
.build();
this.webTestClient
.get().uri("/userIdentity")
.exchange()
.expectStatus().isOk()