From 134f462dab8eba8f2a18d4e760f7ae169eb29240 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 10 Oct 2023 13:23:31 +0300 Subject: [PATCH] Allow @ClientHeaderParam to override User-Agent Fixes: #36329 --- .../reactive/headers/UserAgentTest.java | 25 +++++++++++++++++++ .../reactive/runtime/HeaderFillerUtil.java | 4 +++ .../client/impl/ClientBuilderImpl.java | 2 +- .../client/impl/RestClientRequestContext.java | 1 + 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/headers/UserAgentTest.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/headers/UserAgentTest.java index 7ea164cbc1fdc..6f85bd51de27f 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/headers/UserAgentTest.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/headers/UserAgentTest.java @@ -10,6 +10,7 @@ import jakarta.ws.rs.Path; import org.eclipse.microprofile.rest.client.RestClientBuilder; +import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -36,6 +37,18 @@ void testHeaderOverride() { assertThat(client.callWithUserAgent("custom-agent")).isEqualTo("custom-agent"); } + @Test + void testHeadersWithImplicitValue() { + ClientWithAnnotation client = RestClientBuilder.newBuilder().baseUri(baseUri).build(ClientWithAnnotation.class); + assertThat(client.callWithImplicitValue()).isEqualTo("Annotated"); + } + + @Test + void testHeadersWithExplicitValue() { + ClientWithAnnotation client = RestClientBuilder.newBuilder().baseUri(baseUri).build(ClientWithAnnotation.class); + assertThat(client.callWithExplicitValue("custom-agent")).isEqualTo("custom-agent"); + } + @Path("/") @ApplicationScoped public static class Resource { @@ -56,4 +69,16 @@ public interface Client { String callWithUserAgent(@HeaderParam("User-AgenT") String userAgent); } + @ClientHeaderParam(name = "User-Agent", value = "Annotated") + public interface ClientWithAnnotation { + + @Path("/") + @GET + String callWithImplicitValue(); + + @Path("/") + @GET + String callWithExplicitValue(@HeaderParam("User-Agent") String userAgent); + } + } diff --git a/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/HeaderFillerUtil.java b/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/HeaderFillerUtil.java index 632afb5cef99a..bebe8e1160a0c 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/HeaderFillerUtil.java +++ b/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/HeaderFillerUtil.java @@ -6,6 +6,8 @@ import jakarta.ws.rs.core.HttpHeaders; import jakarta.ws.rs.core.MultivaluedMap; +import org.jboss.resteasy.reactive.client.impl.RestClientRequestContext; + @SuppressWarnings("unused") public final class HeaderFillerUtil { @@ -27,6 +29,8 @@ public static boolean shouldAddHeader(String name, MultivaluedMap