On Wed, 5 Nov 2025 11:58:48 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
>
> Michael McMahon has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   revert unintended spec change to sendResponseHeaders

Thanks for adding the `@apiNote` and explicitely mentionning the value of 
`RSPBODY_CHUNKED`. The new text looks good to me now.

Could be good to double check what would happen if you have something like that:


public void handle(final HttpExchange exchange) throws IOException {
     byte[] bytes = getResponseBody(exchange.getRequestURI());
     long fixedlen = bytes.length == 0 ? RSPBODY_EMPTY : bytes.length;
     exchange.sendResponseHeaders(200, fixedlen);
     try (OutputStream os = exchange.getResponseBody()) {
         os.write(bytes);
     }
}

where `getResponseBody(exchange.getRequestURI());` returns `new byte[0];`
will os.write throw, or will it be no-op?
If it throws then should it be specified that `sendResponseHeaders` closes the 
output stream?

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

PR Review: https://git.openjdk.org/jdk/pull/28132#pullrequestreview-3421685185

Reply via email to