Skip to content

Commit 4f22bf7

Browse files
committed
Take follow-redirects config into account for programmatic client created
This property (as other config properties) is meant to apply to all clients, including ones created programmatically. Users can still override this by using .followRedirects() on the builder
1 parent 62bdeaa commit 4f22bf7

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.quarkus.rest.client.reactive.redirect;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.net.URI;
6+
7+
import jakarta.ws.rs.GET;
8+
import jakarta.ws.rs.Path;
9+
import jakarta.ws.rs.QueryParam;
10+
import jakarta.ws.rs.core.Response;
11+
12+
import org.eclipse.microprofile.rest.client.RestClientBuilder;
13+
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
14+
import org.junit.jupiter.api.Test;
15+
import org.junit.jupiter.api.extension.RegisterExtension;
16+
17+
import io.quarkus.test.QuarkusUnitTest;
18+
import io.quarkus.test.common.http.TestHTTPResource;
19+
20+
public class RedirectTestForProgrammaticClientWithGlobalConfigTest {
21+
22+
@RegisterExtension
23+
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
24+
.withApplicationRoot((jar) -> jar
25+
.addClasses(Client.class, RedirectingResource.class))
26+
.overrideRuntimeConfigKey("quarkus.rest-client.follow-redirects", "true");
27+
28+
@TestHTTPResource
29+
URI uri;
30+
31+
@Test
32+
void shouldRedirect() {
33+
Client client = RestClientBuilder.newBuilder().baseUri(uri).build(Client.class);
34+
Response call = client.call(3);
35+
assertThat(call.getStatus()).isEqualTo(200);
36+
}
37+
38+
@RegisterRestClient(configKey = "cl")
39+
@Path("/redirect/302")
40+
public interface Client {
41+
@GET
42+
Response call(@QueryParam("redirects") Integer redirects);
43+
}
44+
}

extensions/resteasy-reactive/rest-client/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientBuilderImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class RestClientBuilderImpl implements RestClientBuilder {
7171
private final List<ParamConverterProvider> paramConverterProviders = new ArrayList<>();
7272

7373
private URI uri;
74-
private boolean followRedirects;
74+
private Boolean followRedirects;
7575
private QueryParamStyle queryParamStyle;
7676
private MultivaluedMap<String, Object> headers = new CaseInsensitiveMap<>();
7777

@@ -438,7 +438,7 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
438438
exceptionMappers.sort(Comparator.comparingInt(ResponseExceptionMapper::getPriority));
439439
redirectHandlers.sort(Comparator.comparingInt(RedirectHandler::getPriority));
440440
clientBuilder.register(new MicroProfileRestClientResponseFilter(exceptionMappers));
441-
clientBuilder.followRedirects(followRedirects);
441+
clientBuilder.followRedirects(followRedirects != null ? followRedirects : restClients.followRedirects().orElse(false));
442442

443443
RestClientsConfig.RestClientLoggingConfig logging = restClients.logging();
444444

0 commit comments

Comments
 (0)