Skip to content

Commit a31a4f8

Browse files
committed
Copy strategiesConfigurers when cloning WebClient.Builder
This commit fixes the missing `strategiesConfigurers` copy when the `WebClient.Builder` is cloned. Fixes gh-24329
1 parent bdb9f95 commit a31a4f8

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -114,6 +114,7 @@ public DefaultWebClientBuilder(DefaultWebClientBuilder other) {
114114
this.filters = other.filters != null ? new ArrayList<>(other.filters) : null;
115115
this.connector = other.connector;
116116
this.strategies = other.strategies;
117+
this.strategiesConfigurers = other.strategiesConfigurers != null ? new ArrayList<>(other.strategiesConfigurers) : null;
117118
this.exchangeFunction = other.exchangeFunction;
118119
}
119120

spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import java.util.Collections;
2121
import java.util.HashMap;
2222
import java.util.Map;
23+
import java.util.function.Consumer;
2324
import java.util.function.Predicate;
2425

2526
import org.junit.jupiter.api.BeforeEach;
@@ -36,6 +37,7 @@
3637
import org.springframework.http.HttpHeaders;
3738
import org.springframework.http.HttpStatus;
3839
import org.springframework.http.MediaType;
40+
import org.springframework.http.codec.ClientCodecConfigurer;
3941

4042
import static org.assertj.core.api.Assertions.assertThat;
4143
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -231,6 +233,23 @@ public void mutateDoesCopy() {
231233
builder1a.defaultCookies(cookies -> assertThat(cookies.size()).isEqualTo(2));
232234
}
233235

236+
@Test
237+
void cloneBuilder() {
238+
Consumer<ClientCodecConfigurer> codecsConfig = c -> {};
239+
ExchangeFunction exchangeFunction = request -> Mono.empty();
240+
WebClient.Builder builder = WebClient.builder().baseUrl("https://example.org")
241+
.exchangeFunction(exchangeFunction)
242+
.filter((request, next) -> Mono.empty())
243+
.codecs(codecsConfig);
244+
245+
WebClient.Builder clonedBuilder = builder.clone();
246+
247+
assertThat(clonedBuilder).extracting("baseUrl").isEqualTo("https://example.org");
248+
assertThat(clonedBuilder).extracting("filters").isNotNull();
249+
assertThat(clonedBuilder).extracting("strategiesConfigurers").isNotNull();
250+
assertThat(clonedBuilder).extracting("exchangeFunction").isEqualTo(exchangeFunction);
251+
}
252+
234253
@Test
235254
public void withStringAttribute() {
236255
Map<String, Object> actual = new HashMap<>();

0 commit comments

Comments
 (0)