RFR: 8287134: HttpURLConnection chunked streaming mode doesn't enforce specified size

Michael McMahon michaelm at openjdk.org
Mon Jan 23 11:43:05 UTC 2023


On Mon, 23 Jan 2023 09:04:58 GMT, Conor Cleary <ccleary at openjdk.org> wrote:

> ### **Description**
> When using `HttpURLConnection::setChunkedStreamingMode()`, the current documentation does not make it clear that the `chunklen` parameter refers to the amount of bytes sent on the wire per HTTP/1.1 chunk and _not_ the  payload length per chunk. The `chunklen` parameter takes into account the bytes used for the chunk size header, two CRLF characters and the possible payload length inclusively.
> 
> ### **Summary of Changes & Justification**
> The API text has been updated to reflect the actual behavior of the method as described above to avoid a similar bug being submitted in the future and to make it clear what the `chunklen` parameter specifies.
> 
> This change will require a csr.

src/java.base/share/classes/java/net/HttpURLConnection.java line 285:

> 283:      *          and a minimum payload length of 1 byte. If chunklen is less
> 284:      *          than or equal to 5, a default value will be used.
> 285:      *

I'd suggest something like this:

chunklen The number of bytes to be written in
each chunk, including the chunk header as a
hexadecimal string (minimum of 1 byte), two CRLF's (4 bytes)
and a minimum payload length of 1 byte. If chunklen is less
than or equal to 5, a higher default value will be used.

-------------

PR: https://git.openjdk.org/jdk/pull/12137


More information about the net-dev mailing list