On Tue, 4 Nov 2025 14:10:14 GMT, Michael McMahon <[email protected]> wrote:

> I'd like to return to this issue with a new PR that addresses the usability 
> issue minimally. Namely to define numeric constants
> for the counter-intuitive responseLength values in 
> `HttpExchange.sendResponseHeaders`. The apidoc then refers to the constant 
> names rather than the numeric values.
> 
> I've updated the implementation and some tests (though not all yet) to use 
> the constant names. I'm open to suggestions on the names themselves. Once 
> that is agreed, I'll update the remaining tests and any other call sites in 
> the implementation.
> 
> Thanks,
> Michael

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. 

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`.

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

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

Reply via email to