You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Ramu (Jira)" <ji...@apache.org> on 2019/09/05 01:59:00 UTC

[jira] [Updated] (CAMEL-13880) netty4-http component is setting an invalid "host" HTTP header

     [ https://issues.apache.org/jira/browse/CAMEL-13880?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ramu updated CAMEL-13880:
-------------------------
    Estimated Complexity:   (was: Novice)

> 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
>            Assignee: Ramu
>            Priority: Major
>
> 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)