- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6.1k
8368695: Support 101 switching protocol in jdk.httpserver #27751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| 👋 Welcome back SentryMan! A progress list of the required criteria for merging this PR into  | 
| ❗ This change is not yet ready to be integrated. | 
| @SentryMan The following label will be automatically applied to this pull request: 
 When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. | 
cc9740e    to
    c44eee2      
    Compare
  
    | @SentryMan Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. | 
| Webrevs
 | 
| Is the intention behind this to support websocket? | 
| 
 To speak plainly, my plan is not for adding official websocket support into the JDK. That part I can do on my own, the only thing I lack is access to the input/output streams after sending a 101 code. (the current logic in send headers closes both after sending 101 headers) | 
| Don't get me wrong though, if you guys decide you want to fully support websocket, I'll gladly offer a PR. (But I highly doubt such a thing will happen) | 
| 
 Right, I don't think we want to support websocket. There are plenty of third party implementations out there and it's a bit too far removed from the purpose as a lightweight server, for serving mainly static content. However, if we were to allow this enabling functionality, it would have to be documented and specified, so that other people could use it. I'd have preferred if the general shape of such an "upgrade API" was discussed on the net-dev email list but we can discuss it here, without prejudice to whether it goes ahead or not. As a minimum, the feature would have to be "opt in" by the handler, probably through a new method on HttpExchange and we have to consider the impact on the rest of the API, such as what happens when HttpServer.stop is called. | 
| 
 For me, it was already implied that 101 status could be sent, because the documentation for  
 For http2 I'm in agreement for a new method, as supporting that kind of upgrade is has far more complexity and requires consuming the body before upgrading. For WebSocket though, such a thing can be accomplished cleanly through the current API. Indeed, in some other implementations of  
 Requiring a manual call of  
 Testing locally, calling stop appears to work the same as an extended GET request. What kind of test assertions would you like to see? | 
| 
 In fact, this might be a good way of thinking about it. When you call      server.createContext(
        "/test",
        exchange -> {
          exchange.sendResponseHeaders(200, 0);
          exchange.getResponseBody().write("My Response".getBytes());
          try (var is = exchange.getRequestBody()) {
            is.transferTo(exchange.getResponseBody());
          }
        }); | 
| 
 Right. But your PR changes the request body input stream preemptively, before  | 
| 
 That is true, but it's only for GET requests. Thus it effectively remains optional as regular GET request handlers wouldn't attempt to read the body. | 
| So your proposal is that we support switching protocols only for GET requests, and only for those that have no Content-length header in the request header? | 
| Essentially yes, because that's all that's needed to support implementing the websocket protocol. | 
| But that would be an incompatible change, isn't it? Consider the following: wouldn't that now block forever if the request contains an upgrade header? | 
| 
 That we even return an inputstream for a GET request is pretty strange but yeah that would indeed block forever. I'll fix to keep compatibility. | 
| @SentryMan  | 
| /label remove core-libs, build, client, compiler, core-libs, core-libs, graal, hotspot, i18n, javadoc, nio, security, serviceability, shenandoah | 
| @SentryMan  The  The  The  The  The  The  The  The  The  The  The  | 
UpgradeInputStreamto ensure that the server keeps track of when the upgraded request is closedsendResponseHeaderswill not immediately close the output streamsendResponseHeaderswill use anUndefLengthOutputStreamProgress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27751/head:pull/27751$ git checkout pull/27751Update a local copy of the PR:
$ git checkout pull/27751$ git pull https://git.openjdk.org/jdk.git pull/27751/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 27751View PR using the GUI difftool:
$ git pr show -t 27751Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27751.diff
Using Webrev
Link to Webrev Comment