-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HttpClient/HttpRequestMessage DELETE in netcoreapp2.1 now includes ContentLength: 0 when it didn't in previous netcoreapp versions #26860
Comments
cc: @geoffkizer @karelz @stephentoub Change in behavior due to using SocketsHttpHandler in .NET Core 2.1. |
For what it's worth, https://tools.ietf.org/html/rfc7230 suggests that the <=
|
Ideally there would be a way to give |
Sounds like something we could fix, but I don't think it is critical for servicing 2.1.x. The behavior is border line and likely doesn't hurt too many developers (the code has to be fairly sensitive to implementation details). @Porges what would be benefit of such extensibility beyond compensating for bugs? It seems like a too big hammer to compensate for bugs, I would rather prefer to fix them instead of exposing such API. For logging purposes we should have DiagnosticsSource hooks. |
The question is how to interpret the phrase "the method semantics do not anticipate such a body" from the RFC, as quoted above. Re DELETE, the RFC says:
That's not entirely clear, but the most reasonable interpretation seems to be that DELETE does not "anticipate" a body and we should not send Content-Length: 0 in this case. OPTIONS is even less clear:
I guess for consistency with previous versions, we should not send Content-Length: 0 in this case either. The PATCH method pretty clearly "anticipates" a body, I think. The behavior of previous versions here is arguably incorrect, and is due to the fact that PATCH was not treated as a known method previously. So I'd suggest we change the behavior of DELETE and OPTIONS so that we don't send Content-Length: 0. But as Karel mentions, it's probably not a critical issue. |
All of the below applies to Windows only, I haven't tested on Linux, although maybe I need to...
My service performs shared key signing to generate an auth header. We include the content-length in this signature if the request sets one. This means I need to know if the
HttpClient
will send a request withContent-Length
or not.Unfortunately, .NET Core and .NET Framework seem quite inconsistent about when they include content-length in the request for some request types (
DELETE
for example), and as far as I know there is no way to tell if it will be there or not other than to hardcode it.Right now, .NET Framework always includes
Content-Length: 0
as a header forDELETE
,PATCH
, andOPTIONS
. In netcoreapp versions <= 2.0 it does not includeContent-Length: 0
for those same operations. But starting in netcoreapp 2.1 it seems like it does includeContent-Length: 0
.You can observe this behavior yourself by trying the below code-snippet in netcoreapp <= 2.0 and netcoreapp2.1, and inspect the request using Fiddler or similar
I have a few questions:
HttpClient
/HttpClientHandler
I am missing that controls these defaults?It does look like if I explicitly add an empty body to my DELETE requests like so:
request.Content = new ByteArrayContent(Array.Empty<Byte>());
I can at least force a consistent behavior across netcoreapp versions, so that's probably what I'm going to do, but this change caught my admittedly pretty fragile code by surprise.The text was updated successfully, but these errors were encountered: