RFR: 8331195: Improve com.sun.net.httpserver.HttpExchange usability [v4]
robert engels
duke at openjdk.org
Fri May 3 13:40:53 UTC 2024
On Fri, 3 May 2024 13:23:59 GMT, robert engels <duke at openjdk.org> wrote:
>> src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java line 82:
>>
>>> 80: * @see #sendResponseHeaders(int, long)
>>> 81: * */
>>> 82: public static final long CHUNKED_CONTENT = 0L;
>>
>> I feel a little uneasy about these constant names, if only because the parameter they are intended to be used for is called "`responseLength`"
>>
>> "The response length is chunked content." Feels strange. Really you don't know the response length. Perhaps `responseLength` is what should change?
>
> That is why the new methods were added. Hard to fix this and remain backward compatible. This will allow an automated change to the constants for better readability.
>
> It is still a length - it’s that some length values are sentinels
I think the solution is to document that the length must be greater than 0 or BBC an IllegalArgumentException is thrown.
As I mention in the other comment - there is only really a single use for this - streaming a file of know length.
This could be removed entirely by a sendResponse(code,Body) or a sendResponse(code,File)
I think this is being over analyzed though. It’s been here since JDK 11 - and people have made do. These should be minor changes to improve the readability and usability- not a wholesale redesign of the api.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18955#discussion_r1589217135
More information about the net-dev
mailing list