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

HttpClient adds Content-Length: 0 for a GET request with a BodyPublishers.noBody()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 11
    • core-libs

      JDK-8283544 addressed the issue where HttpClient was adding a Content-Length: 0 request header for a GET request. The test/jdk/java/net/httpclient/ContentLengthHeaderTest.java, which was added as part of that fix, continues to reproduce the original issue if it is changed to issue the GET request as follows:

      diff --git a/test/jdk/java/net/httpclient/ContentLengthHeaderTest.java b/test/jdk/java/net/httpclient/ContentLengthHeaderTest.java
      index 0ff21c23a8f..16b117b8a66 100644
      --- a/test/jdk/java/net/httpclient/ContentLengthHeaderTest.java
      +++ b/test/jdk/java/net/httpclient/ContentLengthHeaderTest.java
      @@ -142,7 +142,7 @@ public void getWithNoBody(Version version, URI uri) throws IOException, Interrup
               testLog.println(version + " Checking GET with no request body");
               HttpRequest req = HttpRequest.newBuilder()
                       .version(version)
      - .GET()
      + .method("GET", HttpRequest.BodyPublishers.noBody())
                       .uri(uri)
                       .build();
               HttpResponse<String> resp = hc.send(req, HttpResponse.BodyHandlers.ofString(UTF_8));

      This ends up generating a request which has the following request headers:

      INFO: HEADERS: REQUEST HEADERS:
        GET /no_body HTTP/1.1
          Content-Length: 0
          Host: 127.0.0.1:12345
          User-Agent: Java-http-client/26-internal

            pnima Prateek Nima
            jpai Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: