CurlHandler : Ensure SendAsync cannot be called twice for the same request
Originally discovered during the PR, ensure that CurlHandler's SendAsync cannot be called on the same HttpRequestMessage more than once.
HttpClient's SendAsync already ensures that. We may need similar guarantee in CurlHandler as well.
This came from @cipop's comment at https://github.com/dotnet/corefx/pull/2473#discussion_r35718272.
It seems like HttpClient handles this for all handlers by doing the check in the public SendAsync: https://github.com/dotnet/corefx/blob/3df365531591bc6b9e6743dac3d18b7387a3894c/src/System.Net.Http/src/System/Net/Http/HttpClient.cs#L342
I don't see WinHttpHandler doing an additional check beyond that.
@davidsh, is there anything to be done here for both CurlHandler and WinHttpHandler?
Since HttpClient checks for it, it is probably sufficient. And anyways, the check for that (HttpRequestMessage.MarkAsSent) is internal to the System.Net.Http assembly. So other handlers can't check for it anyways.
But I will say in looking at this now, it seems that we made a mistake when we did this. We should actually be checking for this in the HttpMessageInvoker base class SendAsync (which is public). Most people just use HttpClient to invoke the handlers. But simple scenarios can use the HttpMessageInvoker as well. That class was created as way to invoke the handler's SendAsync() method without a lot of overhead of HttpClient. The actual handler SendAsync() method is protected and can't be invoked directly. But HttpMessageInvoker is able to call that method being the handler's method is actually marked protected internal and not just protected.
This is a digression from the actual question you asked but I thought I would give this background.
That's good background. Thanks, David.
So it sounds like we can close this (I'll remove the TODO from the CurlHandler source) and then open a separate issue to look at moving that check from HttpClient.SendAsync down into HttpMessageInvoker.SendAsync.
So it sounds like we can close this (I'll remove the TODO from the CurlHandler source) and then open a separate issue to look at moving that check from HttpClient.SendAsync down into HttpMessageInvoker.SendAsync.
We'll also want to do this change in .NET Framework (Desktop) to be consistent. Our team would take care of that.
cc: @CIPop @SidharthNabar