Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion okhttp/src/main/java/feign/okhttp/OkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public feign.Response execute(feign.Request input, feign.Request.Options options
throws IOException {
okhttp3.OkHttpClient requestScoped;
if (delegate.connectTimeoutMillis() != options.connectTimeoutMillis()
|| delegate.readTimeoutMillis() != options.readTimeoutMillis()) {
|| delegate.readTimeoutMillis() != options.readTimeoutMillis()
|| delegate.followRedirects() != options.isFollowRedirects()) {
requestScoped = delegate.newBuilder()
.connectTimeout(options.connectTimeoutMillis(), TimeUnit.MILLISECONDS)
.readTimeout(options.readTimeoutMillis(), TimeUnit.MILLISECONDS)
Expand Down
12 changes: 10 additions & 2 deletions okhttp/src/test/java/feign/okhttp/OkHttpClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import feign.client.AbstractClientTest;
import feign.Feign;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import okhttp3.mockwebserver.MockResponse;
import org.assertj.core.data.MapEntry;
import org.junit.Test;
Expand Down Expand Up @@ -60,9 +61,14 @@ public void testContentTypeWithoutCharset() throws Exception {
public void testNoFollowRedirect() throws Exception {
server.enqueue(
new MockResponse().setResponseCode(302).addHeader("Location", server.url("redirect")));
// Enqueue a response to fail fast if the redirect is followed, instead of waiting for the
// timeout
server.enqueue(new MockResponse().setBody("Hello"));

OkHttpClientTestInterface api = newBuilder()
.options(new Request.Options(1000, 1000, false))
// Use the same connect and read timeouts as the OkHttp default
.options(new Request.Options(10_000, TimeUnit.MILLISECONDS, 10_000, TimeUnit.MILLISECONDS,
false))
.target(OkHttpClientTestInterface.class, "http://localhost:" + server.getPort());

Response response = api.get();
Expand All @@ -83,7 +89,9 @@ public void testFollowRedirect() throws Exception {
server.enqueue(new MockResponse().setBody(expectedBody));

OkHttpClientTestInterface api = newBuilder()
.options(new Request.Options(1000, 1000, true))
// Use the same connect and read timeouts as the OkHttp default
.options(new Request.Options(10_000, TimeUnit.MILLISECONDS, 10_000, TimeUnit.MILLISECONDS,
true))
.target(OkHttpClientTestInterface.class, "http://localhost:" + server.getPort());

Response response = api.get();
Expand Down