runtime icon indicating copy to clipboard operation
runtime copied to clipboard

CurlHandler : Ensure SendAsync cannot be called twice for the same request

Open kapilash opened this issue 11 years ago • 4 comments

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.

kapilash avatar Sep 16 '15 11:09 kapilash

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?

stephentoub avatar Oct 08 '15 13:10 stephentoub

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.

davidsh avatar Oct 08 '15 14:10 davidsh

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.

stephentoub avatar Oct 08 '15 14:10 stephentoub

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

davidsh avatar Oct 08 '15 15:10 davidsh