Better support for HTTP/2 in SignalR .NET client#42817
Better support for HTTP/2 in SignalR .NET client#42817adityamandaleeka merged 7 commits intorelease/7.0-rc1from
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();
} |
halter73
left a comment
There was a problem hiding this comment.
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
HttpClientto theWebSocketTransportso that WebSockets over HTTP/2.0 can reuse the potentially already HTTP/2 connection.I'm leaning towards not specifying
webSocket.Options.HttpVersion = HttpVersion.Version20by 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.ConnectAsyncmethod.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.ConnectAsyncfor HTTP/1.1 currently. And we should probably document this behavior when setting HTTP/2.