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

HTTP 1.1 Host header be dealt wrongly in proxy & load balancer

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.9.5, 2.10.3, 2.11.0
    • Fix Version/s: 2.17.1, 2.18.0
    • Component/s: camel-http, camel-http4
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      I have wrote code below make camel as a load balancer, but camel-http4(and the camel-http, etc) deal the http header Host wrongly, it replace the Host header with the host name of the backend of balancer, that make the backend generate the wrong link.

      Main.java
      import org.apache.camel.impl.DefaultCamelContext;
      import org.apache.camel.model.RouteDefinition;
      
      public class Main {
          public static void main(String[] args) throws Exception {
              DefaultCamelContext context = new DefaultCamelContext();
      
              RouteDefinition route = new RouteDefinition();
              route.from("jetty:http://0.0.0.0:8080/?matchOnUriPrefix=true")
                      .loadBalance().roundRobin()
                      .to("http4://127.0.0.1:8081/?bridgeEndpoint=true&throwExceptionOnFailure=false")
                      .to("http4://127.0.0.1:8082/?bridgeEndpoint=true&throwExceptionOnFailure=false");
              //
              context.addRouteDefinition(route);
              context.start();
          }
      }
      
      

      I have view the code and found a fix of https://issues.apache.org/jira/browse/CAMEL-5757(See the commit), it's commits simply removed the host header https://fisheye6.atlassian.com/browse/camel-git/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java?hb=true#to106. and I really do not think it should be dealt like that.

      Some backend will use the Host header to generate link, and when the Host header removed and then it be set to the backend's host, the backend got the wrong Host, and generate the wrong link.

      I expect the link should be http://localhost:8080/web but it generate http://127.0.0.1:8081/web or http://127.0.0.1:8082/web when I view the page with the url http://localhost:8080

        Attachments

          Activity

            People

            • Assignee:
              acosentino Andrea Cosentino
              Reporter:
              hu2008yinxiang Ian Hu
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: