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

HttpClient GET method adds Content-Length: 0 header

XMLWordPrintable

    • b23
    • generic
    • generic
    • Verified

        A DESCRIPTION OF THE PROBLEM :
        Using HttpRequest.newBuilder() to create a simple GET() request, and executing it using HttpClient's send() method sends an HTTP 1.1 header containing the content-length: 0 header+value.
        Quite some services die on this header because they do not expect a body related header for a get.

        The code in question is in Http1Request method headers() which contains:
                if (contentLength == 0) {
                    systemHeadersBuilder.setHeader("Content-Length", "0");
                } else if (contentLength > 0) {
                    systemHeadersBuilder.setHeader("Content-Length", Long.toString(contentLength));
                    streaming = false;
                } else {
                    streaming = true;
                    systemHeadersBuilder.setHeader("Transfer-encoding", "chunked");
                }

        This always sends a body related header. It should probably skip this part altogether for a GET.


        FREQUENCY : always


              ccleary Conor Cleary (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: