Göran Erkstam created CAMEL-13880:
-------------------------------------
Summary: netty4-http component is setting an invalid "host" HTTP
header
Key: CAMEL-13880
URL: https://issues.apache.org/jira/browse/CAMEL-13880
Project: Camel
Issue Type: Bug
Components: camel-netty4-http
Affects Versions: 2.24.0
Reporter: Göran Erkstam
The netty4-http component is setting an invalid "host" HTTP header when no port
is defined in the uri for requests.
netty4-http sets the header in DefaultNettyHttpBinding.toNettyRequest where URI
is used to parse the uri string but URI give -1 if no port is defined. For
example the host header could be set to "hostname:-1" which is not accepted of
some proxy servers that check the validity of the host header. For example
Apache proxy will return a http error 400(Bad request).
See [https://tools.ietf.org/html/rfc7230#section-5.4]
{code:java}
// This is how it's done in DefaultNettyHttpBinding.toNettyRequest
URI u = new URI(uri);
String hostHeader = u.getHost() + (u.getPort() == 80 ? "" : ":" + u.getPort());
request.headers().set(HttpHeaderNames.HOST.toString(), hostHeader);
LOG.trace("Host: {}", hostHeader);
{code}
{{}}
One solution could be:
{code:java}
URI u = new URI(uri);
int port = u.getPort();
String hostHeader = u.getHost() + (port == 80 || port ==-1 ? "" : ":" + port);
request.headers().set(HttpHeaderNames.HOST.toString(), hostHeader);
{code}
--
This message was sent by Atlassian Jira
(v8.3.2#803003)