-
Notifications
You must be signed in to change notification settings - Fork 41k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable redirects by default in TestRestTemplate for all HTTP clients #27360
Comments
|
Thanks for the suggestion. As described in the javadoc, the current behaviour is expected:
We can explore the possibility of doing the same for other clients. |
Or provide a mutate method |
@philwebb EDIT: it's caused by |
…lientOption.ENABLE_REDIRECTS` Closes spring-projectsGH-27360
…lientOption.ENABLE_REDIRECTS` Closes spring-projectsGH-27360
…emoval of Apache HttpClient in Spring Framework 6 Spring Boot 3 uses Spring Framework 6, which no longer includes support for Apache HttpClient. As a result, tests failed due to the underlying OkHttp3 client redirecting requests differently. Error Details: ``` AuthConfigTest > forwardWithCorrectCreds() FAILED org.opentest4j.AssertionFailedError: expected: 302 FOUND but was: 200 OK at java.base@17.0.13/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base@17.0.13/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base@17.0.13/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base@17.0.13/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at app//com.netflix.spinnaker.gate.AuthConfigTest.forwardWithCorrectCreds(AuthConfigTest.java:134) ``` For more details, refer below docs: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#apache-httpclient-in-resttemplate spring-projects/spring-boot#27360 (comment)
My test is broken after
rest-assured
dependency removed, I found it caused byTestRestTemplate
inconsistent follow redirects.TestRestTemplate
will use apache httpclient sinceorg.apache.httpcomponents: httpclient
is introduced byrest-assured
, following redirects is disabled by default, thanks to #1497, you can enable it by passingHttpClientOption.ENABLE_REDIRECTS
.If apache httpclient is not present,
TestRestTemplate
will fallback to okhttp3:spring-boot/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactorySupplier.java
Lines 41 to 45 in 47516b5
okhttp3 enable following redirects by default, I think
TestRestTemplate
should keep same behavior not matter which underlying implementation, disabling following redirects is sensible since test want to know which url is redirected to, and it would be better if this option can be mutated.The text was updated successfully, but these errors were encountered: