Skip to content

Commit 9d364d2

Browse files
authored
Merge pull request quarkusio#36377 from geoand/quarkusio#36329
Allow @ClientHeaderParam to override User-Agent
2 parents d3a055f + 134f462 commit 9d364d2

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/headers/UserAgentTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import jakarta.ws.rs.Path;
1111

1212
import org.eclipse.microprofile.rest.client.RestClientBuilder;
13+
import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam;
1314
import org.junit.jupiter.api.Test;
1415
import org.junit.jupiter.api.extension.RegisterExtension;
1516

@@ -36,6 +37,18 @@ void testHeaderOverride() {
3637
assertThat(client.callWithUserAgent("custom-agent")).isEqualTo("custom-agent");
3738
}
3839

40+
@Test
41+
void testHeadersWithImplicitValue() {
42+
ClientWithAnnotation client = RestClientBuilder.newBuilder().baseUri(baseUri).build(ClientWithAnnotation.class);
43+
assertThat(client.callWithImplicitValue()).isEqualTo("Annotated");
44+
}
45+
46+
@Test
47+
void testHeadersWithExplicitValue() {
48+
ClientWithAnnotation client = RestClientBuilder.newBuilder().baseUri(baseUri).build(ClientWithAnnotation.class);
49+
assertThat(client.callWithExplicitValue("custom-agent")).isEqualTo("custom-agent");
50+
}
51+
3952
@Path("/")
4053
@ApplicationScoped
4154
public static class Resource {
@@ -56,4 +69,16 @@ public interface Client {
5669
String callWithUserAgent(@HeaderParam("User-AgenT") String userAgent);
5770
}
5871

72+
@ClientHeaderParam(name = "User-Agent", value = "Annotated")
73+
public interface ClientWithAnnotation {
74+
75+
@Path("/")
76+
@GET
77+
String callWithImplicitValue();
78+
79+
@Path("/")
80+
@GET
81+
String callWithExplicitValue(@HeaderParam("User-Agent") String userAgent);
82+
}
83+
5984
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import jakarta.ws.rs.core.HttpHeaders;
77
import jakarta.ws.rs.core.MultivaluedMap;
88

9+
import org.jboss.resteasy.reactive.client.impl.RestClientRequestContext;
10+
911
@SuppressWarnings("unused")
1012
public final class HeaderFillerUtil {
1113

@@ -27,6 +29,8 @@ public static boolean shouldAddHeader(String name, MultivaluedMap<String, String
2729
// if the header is the Content-Type, then we should update if its current value equals what determined at build time (and therefore no other code has changed it)
2830
return existingValue.equals(defaultContentType);
2931
}
32+
} else if (HttpHeaders.USER_AGENT.equals(name)) {
33+
return RestClientRequestContext.DEFAULT_USER_AGENT_VALUE.equals(existingValue);
3034
} else {
3135
return false;
3236
}

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientBuilderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class ClientBuilderImpl extends ClientBuilder {
7575
private MultiQueryParamMode multiQueryParamMode;
7676

7777
private ClientLogger clientLogger = new DefaultClientLogger();
78-
private String userAgent = "Resteasy Reactive Client";
78+
private String userAgent = RestClientRequestContext.DEFAULT_USER_AGENT_VALUE;
7979

8080
private boolean enableCompression;
8181

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/RestClientRequestContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class RestClientRequestContext extends AbstractResteasyReactiveContext<Re
5858
public static final String INVOKED_METHOD_PROP = "org.eclipse.microprofile.rest.client.invokedMethod";
5959
public static final String INVOKED_METHOD_PARAMETERS_PROP = "io.quarkus.rest.client.invokedMethodParameters";
6060
public static final String DEFAULT_CONTENT_TYPE_PROP = "io.quarkus.rest.client.defaultContentType";
61+
public static final String DEFAULT_USER_AGENT_VALUE = "Resteasy Reactive Client";
6162
private static final String TMP_FILE_PATH_KEY = "tmp_file_path";
6263

6364
static final MediaType IGNORED_MEDIA_TYPE = new MediaType("ignored", "ignored");

0 commit comments

Comments
 (0)