On Tue, 30 Apr 2024 15:35:10 GMT, Daniel Fuchs <[email protected]> wrote:
>> src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java
>> line 246:
>>
>>> 244: * @see HttpExchange#sendResponseHeaders(int, long)
>>> 245: */
>>> 246: public final void sendResponseHeaders(int code,byte[] data) throws
>>> IOException {
>>
>> I'd prefer to drop this method. Some time in the future we might come up
>> with a better mechanism for handling request and response bodies and
>> translating them to higher level types.
>
> If we keep this method then I think it should be named `sendResponse` since
> it sends the response (and not only the headers). It seems a bit limiting
> that it requires a single byte array - but on the other hand that's what we
> use in probably 80% of the tests. On the other hand it seems to promote a
> single `byte[]` array as first class citizen - and as @Michael-Mc-Mahon
> says, that might not be the best choice. Agreed that we can discuss it though.
I think sendResponse() make more sense to me. We could also add a OutputStream
sendResponse(int code,int length), and/or add OutputStream
sendResponseChunked(int code) and try to break the dependency on the
sendResponseHeaders obtuse length parameter.
In reality though, it is either going to be a simple byte array/string, or it
is probably best sent using an output stream - and using a fixed length stream
for that rather than chunked is inefficient because you need to buffer the
entire response (unless you know it ahead of time like in a file transfer) - so
that should be avoided.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18955#discussion_r1585106831