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.
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
fix: improve fallback to null on empty responses #2285
fix: improve fallback to null on empty responses #2285
Changes from 2 commits
f73ff71
79d88f4
9c02075
61ad86e
eac00c9
0f9dcff
1591321
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the value help with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for adding the byte sequence for "null" to the response stream, in the case that the response stream is unexpectedly empty.
So we return
null
instead of throwing an exception.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that cause a side effect that user won't understand why their response becomes
"null"
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarification: The response won't become the String
"null"
, it would become the valuenull
after the json decoder decodes that byte sequence.It has always been the behavior of Dio to return
null
when theResponseType
is.json
and the response is empty.Only in the recent release with the
FusedTransformer
there is now a corner case that ifResponseType
is.json
andContent-Type
header isapplication/json
andContent-Length
header has a value of > 0 andThat an exception is thrown (instead of the old behavior of returning null).
This is because we currently assume that if the
Content-Length
is>0
, that the response body will not be empty. So the response stream is fed into the json decoder, but the decoder throws on empty streams.This transformation is not applied for other
ResponseType
than.json
.I would also be okay with removing the behavior of returning null on empty responses when the
ResponseType
is.json
but the body is empty completely, and always throw an exception in that case.But that would be a breaking change for sure.
The behavior of the current release, where it mostly returns
null
on empty responses but throws an exception in certain corner cases (mostly responses that are invalid according to the HTTP spec, but still occur in the real world), is not ideal IMO.