Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] jetty-client: don't send default User-Agent field

Hi,

On Fri, Sep 22, 2017 at 6:40 PM, Steven Schlansker
<stevenschlansker@xxxxxxxxx> wrote:
> Hi jetty-users,
>
> I am writing a HTTP proxy that calls remote services by jetty-client.
> I do not want the proxy to modify user agent headers, it should be whatever
> the incoming request says (we do UA-detection on the far side).
>
> HttpRequest does something reasonable:
>
>     HttpField userAgentField = client.getUserAgentField();
>     if (userAgentField != null)
>         headers.put(userAgentField);
>
> but HttpClient says no:
>
>     public void setUserAgentField(HttpField agent)
>     {
>         if (agent.getHeader() != HttpHeader.USER_AGENT)
>             throw new IllegalArgumentException();
>         this.agentField = agent;
>     }
>
> throws NPE.
>
> What's the right way to have the client not muck with UA?  Should we
> relax the setter to allow setUserAgentField(null)?  I can subclass
> but that's a little obnoxious just for this...

I don't understand.
The user agent you set on HttpClient would be the default one to use.
Why are you calling httpClient.setUserAgentField(null) ?

-- 
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.


Back to the top