-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Better support for HTTP/2 in SignalR .NET client #42817
Conversation
Hmm, issue with this change is that now all the |
d6c0524
to
21b5175
Compare
src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs
Show resolved
Hide resolved
src/SignalR/clients/csharp/Http.Connections.Client/src/HttpConnection.cs
Show resolved
Hide resolved
src/SignalR/clients/csharp/Http.Connections.Client/src/HttpConnectionOptions.cs
Show resolved
Hide resolved
How hard is it now to force HTTP/1.1 for all requests to get the old behavior if you really want to? |
In order to force HTTP/1.1 on all requests now (if for some reason ALPN negotiation isn't gracefully falling back to HTTP/1.1 or some other reason), you can write the following code: private class Http11Handler : DelegatingHandler
{
public Http11Handler(HttpMessageHandler handler)
: base(handler)
{ }
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.Version = HttpVersion.Version11;
return base.SendAsync(request, cancellationToken);
}
}
HubConnection CreateConnection()
{
return new HubConnectionBuilder().WithUrl(url, options =>
{
options.HttpMessageHandlerFactory = handler =>
{
return new Http11Handler((HttpClientHandler)handler);
};
}).Build();
} |
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 figured it might take something difficult like a DelegatingHandler to revert to the old behavior, but at least there's a way. Hopefully nobody will need to.
@BrennanConroy, this change will be considered for inclusion in the blog post for the release it'll ship in. Nice work! Please ensure that the original comment in this thread contains a clear explanation of what the change does, why it's important (what problem does it solve?), and, if relevant, include things like code samples and/or performance numbers. This content may not be exactly what goes into the blog post, but it will help the team putting together the announcement. Thanks! |
@adityamandaleeka Additional testing added. Approve and merge at will 😃 |
Thanks @BrennanConroy! |
We don't need to specify HTTP/1.1 for negotiate and sends anymore due to #17081 being fixed on all supported server versions!
This change also flows the
HttpClient
to theWebSocketTransport
so that WebSockets over HTTP/2.0 can reuse the potentially already HTTP/2 connection.I'm leaning towards not specifying
webSocket.Options.HttpVersion = HttpVersion.Version20
by default and letting customers specify it viaHttpConnectionOptions.WebSocketConfiguration
. While the connection should fallback to HTTP/1.1 if HTTP/2 isn't supported, it would add additional connection startup latency in those cases.Blocked on a few issues in Runtime around the newClientWebSocket.ConnectAsync
method.Unfortunately, when using HTTP/2 websockets, settings like cookie and certs on the websocket options are ignored and the HttpClient settings are used instead. This is why the PR avoids passing the HttpClient to
WebSocket.ConnectAsync
for HTTP/1.1 currently. And we should probably document this behavior when setting HTTP/2.