If one may want to use a custom HttpClienthandler (for ex. to use Http/2 or a proxy, like socks sharp),IHttpClientFactory has to be implemented.
The easiest way to do this would be to inherit from HttpClientFactory and override CreateSimpleClientHandler. But currently it is not virtual and not overridable. I would ask you kindly to fix this issue.
I'll look at this tomorrow. I doubt that we'd use inheritance for this - that tends to create problems later on. But I'll have a look.
What solution to this problem would you recommend? Maybe injection or a HttpClientHandlerFactory?
I can't say yet, as I haven't looked into it. I don't want to speculate without having done the research.
Okay, looking further, perhaps renaming CreateSimpleClientHandler and then making it virtual would be appropriate. I've asked @chrisdunelm to have a look.
We need to be absolutely clear about what will be done automatically - for example, the current implementation disables redirection and decompression automatically. If we want to preserve that, we may need a new method instead, which is basically a Func<HttpClientHandler>. We need to be careful to document the implications of reuse, as well - it would be bad to use the same handler for two different HttpClients that are configured differently.
Yes, I think it should be OK if we rename the current CreateSimpleClientHandler method to something like CreateAndConfigureSimpleClientHandler, then create a virtual method named CreateSimpleClientHandler. I.e.:
```C#
protected virtual HttpClientHandler CreateSimpleClientHandler() => new HttpClientHandler();
private HttpClientHandler CreateAndConfigureSimpleClientHandler()
{
var handler = CreateSimpleClientHandler();
// The rest of this method identical to how CreateSimpleClientHandler() used to be.
if (handler.SupportsRedirectConfiguration)
{
handler.AllowAutoRedirect = false;
}
if (handler.SupportsAutomaticDecompression)
{
handler.AutomaticDecompression = DecompressionMethods.None;
}
return handler;
}
```
As @jskeet says, we'll need to document in CreateSimpleClientHandler() how redirect and compression will be configured.
Awesome!
Is there already a plan when it will be released on nuget or is there a nightly build? I havent found one :/
There's no specific schedule. I expect it'll be released sometime next week.
There's no specific schedule. I expect it'll be released sometime next week.
Any news? 馃槄
This was released a while ago - sorry for not announcing!
Most helpful comment
This was released a while ago - sorry for not announcing!