-
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
Provide better json support for servers don't support chunked request body #49357
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsBackground
However, there are certain amount of web servers don't support chunked encoding in request body, namely PHP. They would see chunked encoding as empty request. Discovering such issue is not straight. The current workaround is to use var content = JsonContent.Create<T>(json);
await content.LoadIntoBufferAsync();
var response = await httpClient.PostAsync(url, content); This is hard to discover, and prevents the usage of Possible solutions
|
Are you sure this is not some PHP (or Apache/nginx etc.) configuration that you're missing? It seems very weird that it would straight up not support chunked encoding. If you are sure, has an issue been filed with PHP? It lacking support for a major part of the HTTP/1.1 standard is very strange and should be looked at. I'm generally against adding workarounds when we're spec compliant. But, PHP being a large platform does make this more compelling. If we can verify that this is a limitation there, it might make sense to add an API to always buffer request content. |
I agree that compensating for missing HTTP/1.1 standard implementation feels weird. |
Can we improve the docs to show the above and not recommend buffering for large JSON payloads |
The answer is Yes, but it not I'm missing. The developers of certain popular sites/rpc peers misses it. Search for "php chunked request", the first issue from StackOverflow indicates that it needs user-side explicit handling in PHP. Given that the popular browser doesn't use it, and popular tools like curl may not be using it, it's hard to say that this HTTP standard is widely obeyed. |
Background
JsonContent
andPostAsJsonAsync
provided good support for calling json web apis. To save buffer usage, it serializes directly into send buffer, which doesn't calculate content length before serialization, and uses chunked encoding.However, there are certain amount of web servers don't support chunked encoding in request body, namely PHP. They would see chunked encoding as empty request. Discovering such issue is not straight.
The current workaround is to use
LoadIntoBufferAsync
:This is hard to discover, and prevents the usage of
PostAsJsonAsync
.Possible solutions
JsonContent.Create
andPostAsJsonAsync
, with a parameter indicating whether to use chunked encoding.This can add a large amount of overloads.
Can downgrade performance for servers do support chunked request
The change is too broad
The text was updated successfully, but these errors were encountered: