CodingAleCR / http_interceptor

A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.
MIT License
133 stars 67 forks source link

type 'Response' is not a subtype of type 'StreamedResponse' in type cast #134

Open antonshkurenko opened 10 months ago

antonshkurenko commented 10 months ago

Describe the bug Hey guys, I'm using ^2.0.0-beta.7. I have this error in two cases (100% of time): 1) Any time I use send method in the client (https://pub.dev/documentation/http/latest/http/Client/send.html) 2) When I provide client to the CacheManager's config here: https://pub.dev/documentation/flutter_cache_manager/latest/flutter_cache_manager/HttpFileService/HttpFileService.html

It looks like it somehow just force casts and crashes every time here: https://github.com/CodingAleCR/http_interceptor/blob/main/lib/http/intercepted_client.dart#L222

Expected behavior No crashes

Please complete the following information):

miguelruivo commented 1 week ago

I'll have to fork because of this. The Response shouldn't be casted to StreamedResponse specially when the shouldInterceptResponse is set to false.

CodingAleCR commented 1 week ago

I don't know how I missed this and it has stayed like this so long. Thank you for reporting it and for the subsequent comment that surfaced this. I'll look into it as soon as possible.

PRs are welcomed in any case if you also find a fix for this. 🙏🏻

CodingAleCR commented 1 week ago

So, a bit of an insight for future me:

Your CacheManager uses a HttpFileService that underneath makes use of send. So fixing send should be enough of a fix for both scenarios.

CodingAleCR commented 1 week ago

I got a follow up question for you both @miguelruivo @antonshkurenko, what type of request are you sending into send? I ask because send is expected always to return a StreamedResponse (that's coming from http not something from this library) so I don't think the casting is the issue, that's why I want to make sure things are working properly and your answer would help me figure out things. Either that or a repository where I can replicate the issue would be appreciated.

Another ask is if it's still happening on 2.0.0 stable release. There was a pre-release 2.0.0-beta.8 that never got released and had a fix for this.

CodingAleCR commented 1 week ago

I'll add the PR for reference #132