Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8222527

HttpClient doesn't send HOST header when tunelling HTTP/1.1 through http proxy

    Details

    • Subcomponent:
    • Resolved In Build:
      b18
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      A DESCRIPTION OF THE PROBLEM :
      https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host

      HTTP/1.1 requires the Host header be sent - this includes proxies - when using apache with apache_mod_proxy, it returns 400, dutifully honoring the spec

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Watch the following java code in your favorite tcpdump on port 8080; you'll see that only the request line is sent; no Host header

              var httpResponse = HttpClient.newBuilder()
                      .proxy(ProxySelector.of(new InetSocketAddress("localhost", 8080)))
                      .build()
                      .send(HttpRequest.newBuilder(URI.create("https://www.google.com/"))
                              .build(), HttpResponse.BodyHandlers.ofString());
              assert httpResponse.statusCode() == HttpURLConnection.HTTP_OK;


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      CONNECT www.google.com:443 HTTP/1.1\r\n
      Host: www.google.com\r\n
      \r\n

      ACTUAL -
      CONNECT www.google.com:443 HTTP/1.1\r\n
      \r\n


      ---------- BEGIN SOURCE ----------
              var httpResponse = HttpClient.newBuilder()
                      .proxy(ProxySelector.of(new InetSocketAddress("localhost", 8080)))
                      .build()
                      .send(HttpRequest.newBuilder(URI.create("https://www.google.com/"))
                              .build(), HttpResponse.BodyHandlers.ofString());
              assert httpResponse.statusCode() == HttpURLConnection.HTTP_OK;

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              dfuchs Daniel Fuchs
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: