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

XMLWordPrintable

    • Type: Sub-task
    • Resolution: Delivered
    • Priority: P4
    • 26
    • Affects Version/s: 26
    • Component/s: 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`.

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

              Created:
              Updated:
              Resolved: