diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/http/client/AbstractClientHttpRequestFactoryBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/http/client/AbstractClientHttpRequestFactoryBuilder.java index 135b8a4587..a189a5eb66 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/http/client/AbstractClientHttpRequestFactoryBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/http/client/AbstractClientHttpRequestFactoryBuilder.java @@ -41,6 +41,10 @@ abstract class AbstractClientHttpRequestFactoryBuilder> getCustomizers() { + return this.customizers; + } + protected final List> mergedCustomizers(Consumer customizer) { Assert.notNull(this.customizers, "'customizer' must not be null"); return merge(this.customizers, List.of(customizer)); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/http/client/AbstractClientHttpRequestFactoryBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/http/client/AbstractClientHttpRequestFactoryBuilderTests.java index f2f5cff13f..4a117ff69c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/http/client/AbstractClientHttpRequestFactoryBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/http/client/AbstractClientHttpRequestFactoryBuilderTests.java @@ -21,6 +21,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.time.Duration; +import java.util.function.Function; import javax.net.ssl.SSLHandshakeException; @@ -62,6 +63,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @DirtiesUrlFactories abstract class AbstractClientHttpRequestFactoryBuilderTests { + private static final Function ALWAYS_FOUND = (method) -> HttpStatus.FOUND; + private final Class requestFactoryType; private final ClientHttpRequestFactoryBuilder builder; @@ -120,24 +123,31 @@ abstract class AbstractClientHttpRequestFactoryBuilderTests expectedStatusForMethod) throws URISyntaxException, IOException { + HttpStatus expectedStatus = expectedStatusForMethod.apply(httpMethod); TomcatServletWebServerFactory webServerFactory = new TomcatServletWebServerFactory(0); WebServer webServer = webServerFactory .getWebServer((context) -> context.addServlet("test", TestServlet.class).addMapping("/")); @@ -146,12 +156,11 @@ abstract class AbstractClientHttpRequestFactoryBuilderTests ofTestRequestFactory().build(settings)) @@ -62,7 +62,7 @@ class ReflectiveComponentsClientHttpRequestFactoryBuilderTests } @Override - void redirectDontFollow() throws Exception { + void redirectDontFollow(String httpMethod) throws Exception { ClientHttpRequestFactorySettings settings = ClientHttpRequestFactorySettings.defaults() .withRedirects(Redirects.DONT_FOLLOW); assertThatIllegalStateException().isThrownBy(() -> ofTestRequestFactory().build(settings)) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/http/client/SimpleClientHttpRequestFactoryBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/http/client/SimpleClientHttpRequestFactoryBuilderTests.java index ae92de4a2d..aefb561a3d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/http/client/SimpleClientHttpRequestFactoryBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/http/client/SimpleClientHttpRequestFactoryBuilderTests.java @@ -16,6 +16,11 @@ package org.springframework.boot.http.client; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.test.util.ReflectionTestUtils; @@ -42,4 +47,30 @@ class SimpleClientHttpRequestFactoryBuilderTests return (int) ReflectionTestUtils.getField(requestFactory, "readTimeout"); } + @ParameterizedTest + @ValueSource(strings = { "GET", "POST", "PUT", "DELETE" }) + @Override + void redirectDefault(String httpMethod) throws Exception { + super.redirectDefault(httpMethod); + } + + @ParameterizedTest + @ValueSource(strings = { "GET", "POST", "PUT", "DELETE" }) + @Override + void redirectFollow(String httpMethod) throws Exception { + super.redirectFollow(httpMethod); + } + + @ParameterizedTest + @ValueSource(strings = { "GET", "POST", "PUT", "DELETE" }) + @Override + void redirectDontFollow(String httpMethod) throws Exception { + super.redirectDontFollow(httpMethod); + } + + @Override + protected HttpStatus getExpectedRedirect(HttpMethod httpMethod) { + return (httpMethod != HttpMethod.GET) ? HttpStatus.FOUND : HttpStatus.OK; + } + }