RFR: 8368695: Support 101 switching protocol in jdk.httpserver [v5]

Daniel Fuchs dfuchs at openjdk.org
Wed Feb 11 15:37:34 UTC 2026


On Wed, 11 Feb 2026 14:26:54 GMT, Christoph Läubrich <duke at openjdk.org> wrote:

>>> you can even upgrade to HTTP/2 with POST,
>> 
>> Yeah that's something I avoided by restricting to GET methods. Can we consider this thread resolved then?
>> 
>>> As Upgrade is not and never was supported here, a client handler can't upgrade anyways
>> 
>> He is thinking of scenarios where the body might still try to be read even though the connection is not upgraded, it's about backwards compatibility.
>> 
>>> So if you think there is a problem it would be bet to show a minimal reproducer that can then be added as a test-case to proof it is still working.
>> 
>> As the ones trying to propose the feature it is on us to give an airtight case for why it has no problems.
>
>> He is thinking of scenarios where the body might still try to be read even though the connection is not upgraded, it's about backwards compatibility.
> 
> I honestly don't understand the workflow... If I send an Upgrade _request_ and the server answers with lets say 200 after reading the request and writing a response nothing should happen as far as I understand your implementation. Only if the server actually send the switching protocols _response_ then the stream are handled differently..

When you send a clear http request to a server using the java.net.http client, by default the client will send an HTTP/1.1 request and upgrade headers to upgrade to HTTP/2 will be included. If the server side doesn't supports HTTP/2 it replies with HTTP/1.1. If the server supports HTTP/2 it reads the request body using HTTP/1.1, if applicable, and then sends back 101 and upgrades the connection. The rest of the exchange happens over HTTP/2.
Since the body of the request (if present) is sent using HTTP/1.1, it might use `Transfer-Encoding: chunked`; Only after the body has been read can the connection be upgraded to HTTP/2. But if the server side doesn't support the upgrade it just ignore those headers, reads the body as normal, sends 200, and sends the response body as usual. 

Limiting support for upgrade to GET requests in the HttpServer is not unreasonable. It means that if you want to support upgrade to HTTP/2 you will only have partial support, but since the HTTP/2 upgrade mechanism has been deprecated it's probably not a problem. 

At this time I'm probably more concerned about the implication of supporting upgrade in this way, and the impact on connection life cycle, and management of the server connection pool.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27989#discussion_r2793963256


More information about the net-dev mailing list