Learner
Learner

Reputation: 1323

How to override the default Host request header using Jetty HTTP Client v9?

I am using Jetty client v9 to issue requests to a server. The address of the server I specify has to be in the form of actual (numeric) IP address for various reasons not important for this question, but I would like to pass the assumed host name (i.e. FQDN, not numeric) in the Host header. I've tried the following:

request = httpClient.newRequest(url);
request.method(HttpMethod.GET);
...
request.header(HttpHeader.HOST, hostHeader);

But found that this has no effect. The value of the "Host" header included in the actual request is still the one from the URL (containing the numeric IP address). I did verify that 'hostHeader' variable above does contain the correct value (that I would want).

Can anyone provide some insight as to how to override this default behaviour?

Thanks in advance!

Upvotes: 0

Views: 1949

Answers (1)

sbordet
sbordet

Reputation: 18647

The code you have written is correct, and the value you specify via the header overwrites the one specified in the URI, as expected.

I just committed a test case that captures the use case you described, and works for me.

Perhaps you have a more complex examples that triggers a corner case, and it will be helpful if you can write a reproducible test case. If that is the case, please submit an issue at the Jetty Bugzilla.

Upvotes: 1

Related Questions