Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest Client sets own User-Agent header even if user specifies a different one #23966

Closed
andreas-eberle opened this issue Feb 25, 2022 · 3 comments · Fixed by #24002
Closed

Rest Client sets own User-Agent header even if user specifies a different one #23966

andreas-eberle opened this issue Feb 25, 2022 · 3 comments · Fixed by #24002
Labels
area/rest-client kind/bug Something isn't working
Milestone

Comments

@andreas-eberle
Copy link
Contributor

Describe the bug

This issue is based on the Zulip chat: https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/io.2Evertx.2Ecore.2Ehttp.2Eimpl.2ENoStackTraceTimeoutException

We have a reactive rest client where we set a custom User-Agent header. The user agent needs to be this specific value for the API to accept our request.

@RegisterRestClient(configKey = "xxxxx")
@Produces(MediaType.APPLICATION_JSON)
interface GatewayApi {
    @GET
    @Path("zzzzz")
    suspend fun getUser(
        @HeaderParam("Accept-Language") acceptLanguage: String,
        @HeaderParam("x-request-tracing-id") traceId: String,
        @HeaderParam("x-api-key") apiKey: String,
        @HeaderParam("User-Agent") userAgent: String
    ): Response
}

Unfortunately, it seems that Quarkus versions >= 2.7.0 add an own User-Agent header value with the value: Resteasy Reactive Client. This value is always added, no matter if we set our own User-Agent. So when we make a request the User-Agent header has the values: [Resteasy Reactive Client, Our_Custom_Header_Value] compared to versions <= 2.6.3 where the User-Agent values is [Our_Custom_Header_Value].

A workaround is to add a custom ClientHeadersFactory and register it to above interface. For example:

class GatewayHeadersFactory: ClientHeadersFactory {
    override fun update(incomingHeaders: MultivaluedMap<String, String>?, clientOutgoingHeaders: MultivaluedMap<String, String>?): MultivaluedMap<String, String> {
        val clientHeaders = MultivaluedHashMap<String, String>()
        "Our_Custom_Header_Value".addHeader("User-Agent", clientHeaders)
        return clientHeaders
    }
}

Expected behavior

The rest client should only add its own User-Agent header when we do not specify our own header. This should apply when the header is set with the @HeaderParam annotation in the method as well as when using @ClientHeaderParam to set a User-Agent header.

Actual behavior

The rest client always adds it's own User-Agent header.

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@andreas-eberle andreas-eberle added the kind/bug Something isn't working label Feb 25, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Feb 25, 2022

You added a link to a Zulip discussion, please make sure the description of the issue is comprehensive and doesn't require accessing Zulip.

This message is automatically generated by a bot.

@quarkus-bot
Copy link

quarkus-bot bot commented Feb 25, 2022

/cc @michalszynkiewicz

@michalszynkiewicz
Copy link
Member

@stuartwdouglas I'll change it so that only if the User-Agent is not set, the default value is set.

michalszynkiewicz added a commit to michalszynkiewicz/quarkus that referenced this issue Feb 28, 2022
@quarkus-bot quarkus-bot bot added this to the 2.8 - main milestone Mar 1, 2022
@gsmet gsmet modified the milestones: 2.8 - main, 2.7.3.Final Mar 1, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest-client kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants