Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-13880

netty4-http component is setting an invalid "host" HTTP header

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.24.0
    • Fix Version/s: 3.0.0
    • Component/s: camel-netty4-http
    • Labels:
      None

      Description

      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

       

      // 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);
      

      {{}}

      One solution could be:

      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);
      

        Attachments

          Activity

            People

            • Assignee:
              ramu11 Ramu
              Reporter:
              urken Göran Erkstam
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: