Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8358942 HttpClient adds Content-Length: 0 for a GET request with a BodyPublishers.noBody()
  3. JDK-8369981

Release Note: HttpClient No Longer Sends the Content-Length Header on Requests With No Body

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Delivered
    • Icon: P4 P4
    • 26
    • 26
    • core-libs

      `java.net.HttpClient` has been updated to stop sending the `Content-Length` header on HTTP/1.1 requests using a [method](https://docs.oracle.com/en/java/javase/25/docs/api/java.net.http/java/net/http/HttpRequest.Builder.html#method(java.lang.String,java.net.http.HttpRequest.BodyPublisher)) other than `POST` or `PUT` when provided with a `BodyPublisher` that reports a `contentLength()` of zero bytes.

      This behavior follows the recommendations in RFC 9110: HTTP Semantics.

      Users who need the header may add it using the HttpRequest Builder. The header is restricted by default, and needs to be allowed by setting the system property `jdk.httpclient.allowRestrictedHeaders` to include `content-length`.

            djelinski Daniel Jelinski
            djelinski Daniel Jelinski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: