-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Implement HTTP/2 WebSockets #70895
Implement HTTP/2 WebSockets #70895
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/ncl Issue DetailsResolves #69669
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only quickly skimmed it and left a few comments... I'll review in more depth once it's out of draft and TODOs are addressed.
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpRequestHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/HttpRequestMessage.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/ref/System.Net.WebSockets.Client.cs
Outdated
Show resolved
Hide resolved
....Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/ClientWebSocketOptions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Browser.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/ref/System.Net.WebSockets.Client.cs
Outdated
Show resolved
Hide resolved
…essage.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
697d7b1
to
71cc887
Compare
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocket.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Chris Ross <Tratcher@Outlook.com>
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpRequestHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/HttpRequestMessage.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Show resolved
Hide resolved
9bd918f
to
f6de72a
Compare
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Browser.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Show resolved
Hide resolved
Co-authored-by: Chris Ross <Tratcher@Outlook.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any tests for the new APIs or functionality. Where are they?
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocket.cs
Outdated
Show resolved
Hide resolved
Our external server doesn't support web sockets over H/2, so I can add only loopback. And interop tests with Kestrel after this will be merged |
Right, that's what I was expecting. |
Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpRequestHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/HttpRequestMessage.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs
Show resolved
Hide resolved
{ | ||
bool disposeHandler = false; | ||
invoker ??= new HttpMessageInvoker(SetupHandler(options, out disposeHandler)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephentoub is there a reason why we never cached the whole invoker, only the handler? We'd create it and just throw away for finalization
Line 143 in 9768606
response = await new HttpMessageInvoker(handler).SendAsync(request, externalAndAbortCancellation.Token).ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not to my knowledge.
break; | ||
} | ||
catch (HttpRequestException ex) when | ||
(ex.Data.Contains("SETTINGS_ENABLE_CONNECT_PROTOCOL") && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct me if I'm wrong, but the exception seems to contain SETTINGS_ENABLE_CONNECT_PROTOCOL only when H2 connection is established but settings did not contain enabling extended connect? What will happen if H2 connection was not established at all (if server is H1 only)?
Also, I am a bit concerned about the whole while(true)
approach. The conditions on when we exit or continue looping are a bit obscured.
We only have 3 options: try only H2, try H2 and then H1, try only H1. Meaning, we only have 2 steps, and the second will only be called if the first was not allowed or not succeeded in a special way. Can we unwind the loop? Something like
res = null
fail if unexpected versions
if (can try H2)
{
try
{
res = do H2 stuff
}
catch when can downgrade
}
if (res == null) // either H2 not requested or it failed with downgrade enabled
{
res = do H1 stuff
}
do stuff with res
Please let me know if I miss something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen if H2 connection was not established at all (if server is H1 only)?
In that case we get HttpRequestException
that I cannot separate from other reasons. I'm not sure if I can add Data
to the exception that is already in use?
src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/ref/System.Net.WebSockets.Client.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs
Show resolved
Hide resolved
clientSocket.Options.HttpVersionPolicy = Http.HttpVersionPolicy.RequestVersionExact; | ||
using var handler = new SocketsHttpHandler(); | ||
handler.SslOptions.RemoteCertificateValidationCallback = delegate { return true; }; | ||
await clientSocket.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have tests that validate:
- sending/receiving with HTTP/2 after connecting?
- downgrading?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Send/receive test for web socket stream is added and now I'm struggling to emulate downgrading, not sure if I can make it today.
Co-authored-by: Stephen Toub <stoub@microsoft.com>
fd61bb2
to
4dbe1c2
Compare
await connection.SendResponseDataAsync(streamId, Array.Empty<byte>(), endStream: true); | ||
}); | ||
|
||
StreamingHttpContent requestContent = new StreamingHttpContent(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed anywhere, is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, I'll remove it
Resolves #69669