RFR: 7026262: HttpServer: improve handling of finished HTTP exchanges

Daniel Fuchs dfuchs at openjdk.org
Fri Mar 24 10:19:34 UTC 2023


On Fri, 24 Mar 2023 07:39:22 GMT, Daniel Jeliński <djelinski at openjdk.org> wrote:

>> src/jdk.httpserver/share/classes/sun/net/httpserver/FixedLengthOutputStream.java line 89:
>> 
>>> 87:             // WriteFinishedEvent was sent already; nothing to do
>>> 88:             return;
>>> 89:         }
>> 
>> Wouldn't it be more correct to have sendResponseHeader close the output stream, and let the output stream `close` generate the write event, rather than having sendResponseHeader generate the event and not doing anything here? Or would there be an issue with the case where the stream is chunked output stream?
>
> `sendResponseStream` could close the stream when called with length = -1; the output stream is always fixed length in that case. I'd need to modify this class to accept zero-length writes even when closed, but I think there's a precedent for that already. Will look into it.

That was just a suggestion - I was a bit bothered with the hidden interaction between FixedLengthOutputStream and sendResponseHeaders here, where FixedLengthOutputStream has to trust that sendResponseHeaders has sent the event. It looked strange. Maybe there are other possibilities - like e.g a ZeroLengthOutputStream :-)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13157#discussion_r1147380698


More information about the net-dev mailing list