Equivalent to WebRequestHandler in .net Core
In .net Framework we could use the WebRequestHandler, which has a UnsafeAuthenticatedConnectionSharing property. That will allow us to send multiple requests while keeping the connection open and without verifying credentials again. This is a huge performance boost when multiple requests are issued to the same host. Is there similar functionality in .net Core ?
@davidsh I can see you added this to future milestone. Does that mean that currently there is no equivalent for this in core?
Does that mean that currently there is no equivalent for this in core?
There is no current equivalent for this in .NET Core.
There is no current equivalent for this in .NET Core.
Does WinHTTP not pool such connections?
Does WinHTTP not pool such connections?
Yes, WinHTTP and WinINet pool and cache connections.
I probably should have clarified my response. While there is no direct replacement for that property (UnsafeAuthenticatedConnectionSharing) from .NET Framework's WebRequestHandler class, it is not clear that it is needed in .NET Core with how the HTTP stacks are already caching connections and HTTP authentication credentials.
It would be best if a small repro could be put together and a network trace to show any possible performance issue with how connections and credentials are currently being used by the HTTP stacks in .NET Core.
cc: @Tratcher who can provide some possible historical background on the use of the 'UnsafeAuthenticatedConnectionSharing' property from WebRequestHandler and whether it's value is still needed/missing from .NET Core HTTP stacks.
NTLM is connection bound authentication and requires that the connection be closed after every request for optimal security. This isn't optimal for performance so UnsafeAuthenticatedConnectionSharing allows overriding this closure and re-using the connection. When you do this you do not re-authenticate on subsequent requests, the server caches the credentials from the first one and re-uses them. Both the client and server have to have this setting enabled for it to work. IIS has this enabled by default. .NET HttpWebRequest and HttpListener did not.
Note this feature should only be used when you're sure you're handling requests for only one user, or properly channeling users to their own connection pools.
So yes the flag may still be relevant. Do you know what WinHttp's default behavior is?
Will there be a similar flag in .net Core ?
Will there be a similar flag in .net Core ?
cc: @geoffkizer @stephentoub @karelz
Perhaps this might be addressed as an extra setting in the new SocketHttpHandler: https://github.com/dotnet/corefx/blob/master/src/System.Net.Http/ref/System.Net.Http.cs#L239
Do we actually need a setting here? Since the pooling is associated with a given handler, I think it's very reasonable to say that you should only share that handler with code you're comfortable sharing connections with. And then there's no need for such a property or the associated complexity in the implementation.
cc: @Tratcher
So yes the flag may still be relevant. Do you know what WinHttp's default behavior is?
At a minimum we need to confirm the defaults on various platforms and see if the experience is consistent. E.g. this feature is disabled by default on .NET Framework for HttpWebRequest & HttpClient.
Do we actually need a setting here? Since the pooling is associated with a given handler, I think it's very reasonable to say that you should only share that handler with code you're comfortable sharing connections with. And then there's no need for such a property or the associated complexity in the implementation.
Agreed. Plus, credentials are specified on the HttpClientHandler, not per-request as in HttpWebRequest. So all connections shared the same credentials, and there's no reason not to always reuse them.
I hear many clever suggestions. Does that mean that there will be support for re-using NTLM-based http-connections in .net Core ?
System.Net.Http.WebRequestHandler seems to be bit more over System.Net.Http.HttpClientHandler than just UnsafeAuthenticatedConnectionSharing.
What's the recommendation for replacing System.Net.Http.WebRequestHandler with System.Net.Http.HttpClientHandler? What should the user look out for?
Does that mean that there will be support for re-using NTLM-based http-connections in .net Core ?
Yes, they are reused.
What should the user look out for?
What from WebRequestHandler are you concerned about?
There was a reason for WebRequestHandler, wasn't it? Apart from the NTLM thing, what should a user migrating to .NET Standard use instead of WebRequestHandler?
In net461 WebRequestHandler used the same implementation as HttpClientHandler, it only exposed more switches that we didn't think would be portable across different implementations (like UnsafeAuthenticatedConnectionSharing). If there wasn't a specific option on WebRequestHandler you were using then you should be able to move to HttpClientHandler.
@Tratcher, I hope so. But I'd like some clear messaging on this.
@paulomorgado @Tratcher In our company, we are required to use NTLM for identity authentication. A move to HttpClientHandler would be a major performance degradation, as http connections cannot be reused.
as http connections cannot be reused
They can. In .NET Core, it's as if UnsafeAuthenticatedConnectionSharing is true. The assumption is that you're only giving out the client/handler to code you're ok reusing your connections. That's a different model from HttpWebRequest, where the pool of connections is essentially static and potentially accessed by all HttpWebRequests.