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

Allow customization of Host header with HttpClient

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Debian Linux testing, 4.15.7 kernel.

      openjdk 11 2018-09-25
      OpenJDK Runtime Environment 18.9 (build 11+28)
      OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)


      A DESCRIPTION OF THE PROBLEM :
      Host header is used in virtual host environments and it is important to be able to customize it.
      Right now following code fails:
      HttpClient client = HttpClient.newHttpClient();
      HttpRequest request = HttpRequest.newBuilder()
          .uri(URI.create("http://127.0.0.1:8081/"))
          .header("Host", "test.example.com")
          .build();
      client.send(request, HttpResponse.BodyHandler.asString());

      With exception: java.lang.IllegalArgumentException: restricted header name: "Host"

      (In JDK 10, it doesn't fail but sends two Host headers, one from URI and the second one from requested).

      This should not be the case.
      Host header should be customizable (like in other http client libraries - sometimes it is called virtualHost), and should override the one that exists in the URI.

      Reported on SO:
        https://stackoverflow.com/questions/52315472/how-to-customise-host-header-in-java-http-client


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jboes Julia Boes
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: