On Tue, 14 Oct 2025 17:34:09 GMT, Josiah Noel <[email protected]> wrote:

>> - adds a flag to ExchangeImpl to signal whether the current request is an 
>> Upgrade request
>> - Adds a new `UpgradeInputStream` to ensure that the server keeps track of 
>> when the upgraded request is closed
>> - on 101 response codes, `sendResponseHeaders` will not immediately close 
>> the output stream 
>> - on 101 response codes, `sendResponseHeaders` will use an 
>> `UndefLengthOutputStream`
>
> Josiah Noel has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   tab

Here is a proposal for discussion. This would be added to the end of the class 
level docs for HttpExchange

`
 <b>Upgrading HTTP/1.1 connections</b>

<br>Sending a 101 response to a request from the client to upgrade to some 
other protocol has the effect of detaching the underlying connection from the 
HTTP stack. The {@link InputStream} and {@link OutputStream} returned from 
{@link #getRequestBody()} and {@link #getResponseBody()} respectively, after 
sending the 101 response, returns raw streams to the underlying socket. {@code 
sendResponseHeaders(101, -1)} must be called prior to obtaining the detached 
input and output streams. It is also an error to send a 101 response if no 
{@code Upgrade} header was present in the request, or the request was anything 
other than a GET (or CONNECT?) or to pass a content length other than {@code 
-1}. Other than that, the library does not restrict or interpret the Upgrade 
header value. It is up to the calling code to implement whatever higher level 
protocol is required over the underlying socket. It is up to the calling code 
to eventually obtain and eventually close both the detached {@link #getRe
 questBody() InputStream} and {@link #getResponseBody() OutputStream} to 
prevent resource leaks. Closing the exchange after {@code 
sendResponseHeaders(101, -1)} has been called has no effect on these streams. 
Terminating the server with {@link HttpServer.stop(int)} closes all sockets 
associated with the server including any sockets detached through this 
mechanism.`

The apidoc for HttpServer.stop would need to mention that sockets detached from 
the upgrade mechanism are also closed.

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

PR Comment: https://git.openjdk.org/jdk/pull/27751#issuecomment-3406670813

Reply via email to