Open quaff opened 3 years ago
Implementation | Default |
---|---|
HttpComponentsClientHttpRequestFactory | false |
OkHttp3ClientHttpRequestFactory | true |
SimpleClientHttpRequestFactory | true |
Thanks for the suggestion. As described in the javadoc, the current behaviour is expected:
If Apache Http Client 4.3.2 or better is available (recommended) it will be used as the client, and by default configured to ignore cookies and redirects.
We can explore the possibility of doing the same for other clients.
Or provide a mutate method withFollowRedirects
like withBasicAuth
for TestRestTemplate
.
@philwebb TestRestTemplate
use FOLLOW_WHEN_POSSIBLE
since 3.4.0, it breaks tests that rely on DONT_FOLLOW
.
EDIT: it's caused by followRedirects
of jdk.internal.net.http.HttpClientImpl
changed from NEVER
to NORMAL
after upgrading to 3.4.0.
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 https://github.com/spring-projects/spring-boot/issues/1497, you can enable it by passingHttpClientOption.ENABLE_REDIRECTS
. If apache httpclient is not present,TestRestTemplate
will fallback to okhttp3: https://github.com/spring-projects/spring-boot/blob/47516b50c39bd6ea924a1f6720ce6d4a71088651/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactorySupplier.java#L41-L45okhttp3 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.