I am using Apache Camel 2.13.1 as a HTTP proxy using the http4 component:
.from("servlet://*?matchOnUriPrefix=true")
.to("http4://example.com/?bridgeEndpoint=true&httpClient.redirectsEnabled=false")
Now I need to set the Host
HTTP header parameter of the outgoing proxy request to the backend system because since it is used by the proxied application to generate absolute links, it has to match the public/frontend url.
Using the naive approach of simply setting the Host
header in the camel message .setHeader("Host", "foo.com")
fails due to the http4 component overriding this with the hostname of the proxied host example.com.
Further research revealed, that HTTPClient used to do this via the virtual-host param. Camel's http4 component supports pass-through HTTPClient params using the httpClient
param. However since version 2.13.0,
camel http4 uses HTTPClient 4.3's builder api (http://camel.apache.org/http4.html) to pass through the httpClient.* params from the endpoint configuration and unfortunately HTTPClient 4.3's builder api does not include the virtual-host param anymore. Judging by this HTTPClient mailing list reply (https://mail-archives.apache.org/mod_mbox//hc-httpclient-users/201312.mbox/%3C1387792931.6163.17.camel@ubuntu%3E) it looks like I may have to set the virtual host, which is appears to be called target host, on the HttpClientContext via setTargetHost. How can I do this via camel in between?
So to sum up: I am using camel's http4 component and need to change the Host
HTTP header value of the outgoing proxy request.