Skip to content

Commit

Permalink
Merge pull request #45492 from geoand/rest-client-global-redirect
Browse files Browse the repository at this point in the history
Take follow-redirects config into account for programmatic client created
  • Loading branch information
geoand authored Jan 12, 2025
2 parents e62c059 + 4f22bf7 commit ec6bf3c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.quarkus.rest.client.reactive.redirect;

import static org.assertj.core.api.Assertions.assertThat;

import java.net.URI;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Response;

import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.quarkus.test.common.http.TestHTTPResource;

public class RedirectTestForProgrammaticClientWithGlobalConfigTest {

@RegisterExtension
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(Client.class, RedirectingResource.class))
.overrideRuntimeConfigKey("quarkus.rest-client.follow-redirects", "true");

@TestHTTPResource
URI uri;

@Test
void shouldRedirect() {
Client client = RestClientBuilder.newBuilder().baseUri(uri).build(Client.class);
Response call = client.call(3);
assertThat(call.getStatus()).isEqualTo(200);
}

@RegisterRestClient(configKey = "cl")
@Path("/redirect/302")
public interface Client {
@GET
Response call(@QueryParam("redirects") Integer redirects);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class RestClientBuilderImpl implements RestClientBuilder {
private final List<ParamConverterProvider> paramConverterProviders = new ArrayList<>();

private URI uri;
private boolean followRedirects;
private Boolean followRedirects;
private QueryParamStyle queryParamStyle;
private MultivaluedMap<String, Object> headers = new CaseInsensitiveMap<>();

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

RestClientsConfig.RestClientLoggingConfig logging = restClients.logging();

Expand Down

0 comments on commit ec6bf3c

Please sign in to comment.