My test is broken after rest-assured dependency removed, I found it caused by TestRestTemplate inconsistent follow redirects. TestRestTemplate will use apache httpclient since org.apache.httpcomponents: httpclient is introduced by rest-assured, following redirects is disabled by default, thanks to #1497, you can enable it by passing HttpClientOption.ENABLE_REDIRECTS.
If apache httpclient is not present, TestRestTemplate will fallback to okhttp3:
|
Map<String, String> candidates = new LinkedHashMap<>(); |
|
candidates.put("org.apache.http.client.HttpClient", |
|
"org.springframework.http.client.HttpComponentsClientHttpRequestFactory"); |
|
candidates.put("okhttp3.OkHttpClient", "org.springframework.http.client.OkHttp3ClientHttpRequestFactory"); |
|
REQUEST_FACTORY_CANDIDATES = Collections.unmodifiableMap(candidates); |
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.
My test is broken after
rest-assureddependency removed, I found it caused byTestRestTemplateinconsistent follow redirects.TestRestTemplatewill use apache httpclient sinceorg.apache.httpcomponents: httpclientis 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,
TestRestTemplatewill 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
TestRestTemplateshould 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.