tmenier / Flurl

Fluent URL builder and testable HTTP client for .NET

Home Page:https://flurl.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request for the use of SocketsHttpHandler

satishviswanathan opened this issue · comments

@tmenier I have started using the version 4.0.0-pre4 and was able to make Http/2 calls. Thank you for this feature addition. if we can have SocketsHttpHandler as the default handler then we can set the properties like EnableMultipleHttp2Connections , connection pooling, Gzip compression etc.

On Http/2 I was able to get it working by setting the global property FlurlHttp.GlobalSettings.HttpVersion = "2.0". It would be great if we can set this per HttpClient also other properties like DefaultVersionPolicy. Currently we can set it at the client level but I ran into the following issue.

 var httpClient = _flurlClientFactory.Get(serviceOptions.Url);
 httpClient.BaseUrl = serviceOptions.Url;
httpClient.HttpClient.DefaultRequestVersion = new Version(2, 0);
httpClient.HttpClient.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;

With the above code if I had a client created once with those properties set then next time when I try to get the same client using the flurl factory and set these properties then we would get the following error.

"System.InvalidOperationException : This instance has already started one or more requests. Properties can only be modified before sending the first request."

In 4.0, SocketsHttpHandler will be used by Flurl on supported platforms and will be easily configurable via IFlurlClientBuilder.ConfigureInnerHandler. See #770 for details.

Heads up: This implementation is changing in prerelease 6 to address #772. Here's the new way:

  • Don't call ConfigureInnerHandler - it will be for configuring an HttpClientHandler on all platforms.
  • Call UseSocketsHttpHandler instead - it will be for configuring a SocketsHttpHandler instead and is only available on supported platforms.

Attempting to call both will throw an exception, so definitely avoid that.