Setting custom User-Agent header

869 views
Skip to first unread message

Pavel Arlovich

unread,
Jun 19, 2015, 11:41:43 AM6/19/15
to dropwiz...@googlegroups.com
Hi All,

We are using Dropwizard version 0.8.1 and JerseyClient created via JerseyClientBuilder.

In our application we are trying to set 'User-Agent' http header for WebTargets.
But the changes don't take place and the requests are always sent with 'User-Agent: <application name>(<client name>)'

Looks like it relates to a new configuration parameter httpClient.userAgent added in v0.7.1: Jun 18 2014
Is there a way to set different user-agents for a different WebTargets or to disable this new feature? Because, for now it seems like a bug.

Thanks.

Carlo Barbara

unread,
Jun 26, 2015, 5:18:04 PM6/26/15
to dropwiz...@googlegroups.com
My understanding is that user agent comes into play in 5 places along the lifecycle of a client and it's request. The first to stamp it on a request wins. 
  1. JerseyClientConfiguration                   This is where we set the client user agent
  2. JerseyInvocation#header                    If set on the jersey client request
  3. ClientRuntime#addUserAgent             If there is no user agent set, it's set user agent on jersey request to a formatting of the apache connector name
  4. DropwizardApacheConnector             This is where we currently ignore the user agent header on the jersey request, and don't stamp it on the apache request.   
  5. RequestUserAgent#process               If there is no user agent set on the request, use the client configuration user agent

You're proposing we don't ignore the jersey user agent when building the apache request, but that won't work as outlined below.

User agent not set on client or request           --> Handled by 3  //Accurate
User agent set on client and request              --> Handled by 2  //Accurate
User agent set on client, not request              --> Handled by 4  //This breaks, as we will stamp the value calculated in 3
User agent not set on client, set on request   --> Handled by 2  //Accurate


Ideally, the way it would work is to use the user agent in this priority, where the first one available wins: request provided, client config provided, client default. Unfortunately, I don't see a way to make it work this way.

--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pavel Arlovich

unread,
Jul 1, 2015, 1:58:49 AM7/1/15
to dropwiz...@googlegroups.com
Why did it work in Dropwizard v0.6.2 ?
Was it because Jersey client worked differently? 
Reply all
Reply to author
Forward
0 new messages