You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Maxime Tremblay <ma...@acprail.com> on 2012/10/26 21:01:24 UTC

Host header not set correctly with camel-http4

Hi All,

I just have to switch to camel-http4 for some request proxying whit
bridgeEnpoint=true.

Now I have the problem that the Host header is not set correctly in the
HTTP request.
The original Host is put instead of the target Host.

Everything was working fine with camel-http.
And I cannot find how to explicitly set the Host, neither in the doc or the
the source code.

This simple route shows the problem:

 <route autoStartup="true" id="TestHost" xmlns:ns2="
http://camel.apache.org/schema/web" xmlns="
http://camel.apache.org/schema/spring">
        <from uri="jetty:http://0.0.0.0:8090/TestHost"/>
        <to uri="https4://
www.google.com?bridgeEndpoint=true&amp;throwExceptionOnFailure=false<http://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false>
"/>
 </route>

This is what I get in the log:

INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
DefaultClientConnection        DEBUG Sending request: GET / HTTP/1.1
INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
wire                           DEBUG >> "GET / HTTP/1.1[\r][\n]"
INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
wire                           DEBUG >> "breadcrumbId:
ID-EROS-1329-1351277552803-0-2[\r][\n]"
INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
wire                           DEBUG >> "User-Agent: Mozilla/5.0 (Windows
NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0[\r][\n]"
INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
wire                           DEBUG >> "Accept-Encoding: gzip,
deflate[\r][\n]"
INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
wire                           DEBUG >> "Host: 10.0.0.6:8090[\r][\n]"
INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
wire                           DEBUG >> "Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8[\r][\n]"
INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
wire                           DEBUG >> "Accept-Language:
en-us,en;q=0.5[\r][\n]"
INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
wire                           DEBUG >> "Connection: Keep-Alive[\r][\n]"
INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
wire                           DEBUG >> "[\r][\n]"

It is problematic in some authentication scenario, were the Host is
verified by the server.

Anyone knows how to get the target host in the Host header of the request
sent ?

Many thanks,

Max

Re: Host header not set correctly with camel-http4

Posted by Maxime Tremblay <ma...@acprail.com>.
Thanks much, your proposed fix is working well.

I opened the jira ticket
https://issues.apache.org/jira/browse/CAMEL-5757for this problem.

Max

On Mon, Oct 29, 2012 at 5:14 AM, Claus Ibsen <cl...@gmail.com> wrote:

> On Fri, Oct 26, 2012 at 9:01 PM, Maxime Tremblay
> <ma...@acprail.com> wrote:
> > Hi All,
> >
> > I just have to switch to camel-http4 for some request proxying whit
> > bridgeEnpoint=true.
> >
> > Now I have the problem that the Host header is not set correctly in the
> > HTTP request.
> > The original Host is put instead of the target Host.
> >
> > Everything was working fine with camel-http.
> > And I cannot find how to explicitly set the Host, neither in the doc or
> the
> > the source code.
> >
>
> I would assume using <setHeader
> headerName="Host"><constant>Foo</constant></setHeader> would override
> the header.
> Or even just remove it.
>
> But I guess we should fix it so it work out of the box. Fell free to
> log a JIRA ticket.
> And as always patches is welcome.
> http://camel.apache.org/contributing.html
>
>
> > This simple route shows the problem:
> >
> >  <route autoStartup="true" id="TestHost" xmlns:ns2="
> > http://camel.apache.org/schema/web" xmlns="
> > http://camel.apache.org/schema/spring">
> >         <from uri="jetty:http://0.0.0.0:8090/TestHost"/>
> >         <to uri="https4://
> > www.google.com?bridgeEndpoint=true&amp;throwExceptionOnFailure=false<
> http://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false>
> > "/>
> >  </route>
> >
> > This is what I get in the log:
> >
> > INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 -
> /TestHost]
> > DefaultClientConnection        DEBUG Sending request: GET / HTTP/1.1
> > INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 -
> /TestHost]
> > wire                           DEBUG >> "GET / HTTP/1.1[\r][\n]"
> > INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 -
> /TestHost]
> > wire                           DEBUG >> "breadcrumbId:
> > ID-EROS-1329-1351277552803-0-2[\r][\n]"
> > INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 -
> /TestHost]
> > wire                           DEBUG >> "User-Agent: Mozilla/5.0 (Windows
> > NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0[\r][\n]"
> > INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 -
> /TestHost]
> > wire                           DEBUG >> "Accept-Encoding: gzip,
> > deflate[\r][\n]"
> > INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 -
> /TestHost]
> > wire                           DEBUG >> "Host: 10.0.0.6:8090[\r][\n]"
> > INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 -
> /TestHost]
> > wire                           DEBUG >> "Accept:
> > text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8[\r][\n]"
> > INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 -
> /TestHost]
> > wire                           DEBUG >> "Accept-Language:
> > en-us,en;q=0.5[\r][\n]"
> > INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 -
> /TestHost]
> > wire                           DEBUG >> "Connection: Keep-Alive[\r][\n]"
> > INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 -
> /TestHost]
> > wire                           DEBUG >> "[\r][\n]"
> >
> > It is problematic in some authentication scenario, were the Host is
> > verified by the server.
> >
> > Anyone knows how to get the target host in the Host header of the request
> > sent ?
> >
> > Many thanks,
> >
> > Max
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: Host header not set correctly with camel-http4

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Oct 26, 2012 at 9:01 PM, Maxime Tremblay
<ma...@acprail.com> wrote:
> Hi All,
>
> I just have to switch to camel-http4 for some request proxying whit
> bridgeEnpoint=true.
>
> Now I have the problem that the Host header is not set correctly in the
> HTTP request.
> The original Host is put instead of the target Host.
>
> Everything was working fine with camel-http.
> And I cannot find how to explicitly set the Host, neither in the doc or the
> the source code.
>

I would assume using <setHeader
headerName="Host"><constant>Foo</constant></setHeader> would override
the header.
Or even just remove it.

But I guess we should fix it so it work out of the box. Fell free to
log a JIRA ticket.
And as always patches is welcome.
http://camel.apache.org/contributing.html


> This simple route shows the problem:
>
>  <route autoStartup="true" id="TestHost" xmlns:ns2="
> http://camel.apache.org/schema/web" xmlns="
> http://camel.apache.org/schema/spring">
>         <from uri="jetty:http://0.0.0.0:8090/TestHost"/>
>         <to uri="https4://
> www.google.com?bridgeEndpoint=true&amp;throwExceptionOnFailure=false<http://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false>
> "/>
>  </route>
>
> This is what I get in the log:
>
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> DefaultClientConnection        DEBUG Sending request: GET / HTTP/1.1
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "GET / HTTP/1.1[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "breadcrumbId:
> ID-EROS-1329-1351277552803-0-2[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "User-Agent: Mozilla/5.0 (Windows
> NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "Accept-Encoding: gzip,
> deflate[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "Host: 10.0.0.6:8090[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "Accept:
> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "Accept-Language:
> en-us,en;q=0.5[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "Connection: Keep-Alive[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "[\r][\n]"
>
> It is problematic in some authentication scenario, were the Host is
> verified by the server.
>
> Anyone knows how to get the target host in the Host header of the request
> sent ?
>
> Many thanks,
>
> Max



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Host header not set correctly with camel-http4

Posted by ogao <ol...@gmail.com>.
Hi,

We are using camel 2.12.0 http4 component to proxy http requests to a web
application. We ran into an issue with the host header being removed for
every proxied request due to this line of code in http4's HttpProducer.java

exchange.getIn().getHeaders().remove("host"); line 106

we found this post when this above line of code has been introduced. We
would like to keep the host header in the http proxy situation. Is there a
way around this other than modifying the existing http4 component source
code?

Thanks!





--
View this message in context: http://camel.465427.n5.nabble.com/Host-header-not-set-correctly-with-camel-http4-tp5721621p5742040.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Host header not set correctly with camel-http4

Posted by Maxime Tremblay <ma...@acprail.com>.
Sorry, just forgot to say that I'm using camel 2.10.1 in this example.

On Fri, Oct 26, 2012 at 3:01 PM, Maxime Tremblay <maximetremblay@acprail.com
> wrote:

> Hi All,
>
> I just have to switch to camel-http4 for some request proxying whit
> bridgeEnpoint=true.
>
> Now I have the problem that the Host header is not set correctly in the
> HTTP request.
> The original Host is put instead of the target Host.
>
> Everything was working fine with camel-http.
> And I cannot find how to explicitly set the Host, neither in the doc or
> the the source code.
>
> This simple route shows the problem:
>
>  <route autoStartup="true" id="TestHost" xmlns:ns2="
> http://camel.apache.org/schema/web" xmlns="
> http://camel.apache.org/schema/spring">
>         <from uri="jetty:http://0.0.0.0:8090/TestHost"/>
>         <to uri="https4://
> www.google.com?bridgeEndpoint=true&amp;throwExceptionOnFailure=false<http://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false>
> "/>
>  </route>
>
> This is what I get in the log:
>
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> DefaultClientConnection        DEBUG Sending request: GET / HTTP/1.1
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "GET / HTTP/1.1[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "breadcrumbId:
> ID-EROS-1329-1351277552803-0-2[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "User-Agent: Mozilla/5.0 (Windows
> NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "Accept-Encoding: gzip,
> deflate[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "Host: 10.0.0.6:8090[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "Accept:
> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "Accept-Language:
> en-us,en;q=0.5[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "Connection: Keep-Alive[\r][\n]"
> INFO   | jvm 1    | 2012/10/26 14:52:48 | [    qtp31541880-35 - /TestHost]
> wire                           DEBUG >> "[\r][\n]"
>
> It is problematic in some authentication scenario, were the Host is
> verified by the server.
>
> Anyone knows how to get the target host in the Host header of the request
> sent ?
>
> Many thanks,
>
> Max
>