Really Buffered JsonContent when buffered is set #1115
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
If fixes the bug #1099.
What is the current behavior?
When the body is serialized (with JsonContent), the data is not buffered because the JsonContent doesn't implement the
TryComputeLength
method (https://github.com/dotnet/runtime/blob/9c3fc566eb916434f8bfe6974e4ddc21ba6e7ff6/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/JsonContent.cs#L55)The settings
RefitSettings.Buffered
is only used when theBody
attribute is set without the propertyBuffered
defined and has no effect when theBody
attribute missing. The buffering is always disabled when the attribute is missing.What is the new behavior?
The request content is buffered, if the buffering is active.
The
RefitSettings.Buffered
is by default equals to false, and have effect even if the Body property is missing.What might this PR break?
The
RefitSettings.Buffered
have now false as default value, so the attributeBody
is without buffering by default.If
RefitSettings.Buffered
is explicitely set to true, all the body are buffered even if the Body attribute is missing.Some users can belived they buffered and it was not the case, so with this fix the memory usage can increase.
Please check if the PR fulfills these requirements
Other information:
The use of
PushStreamContent
(refit/Refit/RequestBuilderImplementation.cs
Line 576 in 64d9101
JsonContent
because it already streams the data. I didn't change this because I don't know Refit enough well to know the other implication.