-
Notifications
You must be signed in to change notification settings - Fork 70
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
Support handling 304 status code in onResponse flow #119
Support handling 304 status code in onResponse flow #119
Conversation
@@ -30,6 +30,16 @@ class DioCacheInterceptor extends Interceptor { | |||
|
|||
final cacheOptions = _getCacheOptions(options); | |||
|
|||
if (cacheOptions.callResponseInterceptorsAfterNotModified) { |
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.
Why do you need this? Can we get rid of callResponseInterceptorsAfterNotModified
?
If RequestOptions has a custom validateStatus
which allows 304 as valid there should be nothing to do here.
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.
I added this because using validateStatus to validate 304's is not transparent to me. You would have to look into the source code of this cache interceptor to know how 304's are handled. Ofcourse this is more an issue with dio (handling not valid responses in onError and never going back to the onResponse flow) and it breaks every other response interceptor.
@@ -83,6 +93,29 @@ class DioCacheInterceptor extends Interceptor { | |||
return; | |||
} | |||
|
|||
// Check if cache response should be used instead of server response |
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.
Please don't duplicate code.
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.
Fair. I will create a method for this.
* PR feedback * Added test for 304 in success response
Updated Pull request with master and requested changes. |
I forgot to remove the field |
Thanks for your contribution. This PR has been reworked internally and is now available in v3.5.0. |
In Dio a
304 not modified
can be configured to be a valid status:BaseOptions(validateStatus: (status) => status != null && ((status >= 200 && status < 300) || status == 304))
This PR allows 304's to be handled in the onResponse flow.
This way (having not modified as a valid status) the usual chain of onResponse interceptors will still trigger, unlike the error flow.