RFR: 8331195: Improve com.sun.net.httpserver.HttpExchange usability

Michael McMahon michaelm at openjdk.org
Tue Nov 4 16:26:55 UTC 2025


On Tue, 4 Nov 2025 16:02:41 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

> This is a good idea, but it kind of hides the fact that passing 0 may not do what you think it does.
> 
> Typically the pitfall is to assume that if you have an array of bytes then you can can call `sendResponseHeaders` with the array length. The API doc of `sendResponseHeaders` should probably make it clear that 0 is a special value, and that `RSPBODY_CHUNKED` is 0.
> 

Actually, that case is not so bad. What happens is that chunked encoding is selected but the response body
content is empty as intended, and it should work. But, maybe we should still highlight it anyway.

> In addition I would suggest adding code snipets showing both cases (one using a byte array and passing `bytes.length == 0 ? RSPBODY_EMPTY : bytes.length` and the other using `RSPBODY_CHUNKED` with e.g. transferring the content of an `InputStream`.

The worse case is expecting a negative value to mean an indefinite (chunked encoded) length. You definitely don't get what you expect in that case.

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

PR Comment: https://git.openjdk.org/jdk/pull/28132#issuecomment-3486869930


More information about the net-dev mailing list