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

Can it be used with MultipartRequest? #95

Closed riskiadi closed 2 years ago

riskiadi commented 2 years ago

How did you use multipart request using interceptor, i cant using interceptor with MultipartRequest() ?

final http = InterceptedHttp.build(interceptors: [Interceptor(),]); var request = http.MultipartRequest("POST", uri);

The method 'MultipartRequest' isn't defined for the type 'InterceptedHttp'. (Documentation)

CodingAleCR commented 2 years ago

Hi, this is not yet supported in the library. However, there's an open PR so hopefully it's coming soon.

98

CodingAleCR commented 2 years ago

Hey, we have a beta version that supports MultipartRequests, let me know if you are willing to try it out, it has a new API so you might need to adjust a few things (check out the guide for more info)

riskiadi commented 2 years ago

Hi, this is not yet supported in the library. However, there's an open PR so hopefully it's coming soon.

98

Yep, I'm so excited, thanks for developing "HTTP interceptor", I will try it later.

dexcell commented 2 years ago

Hi, i'm trying the http interceptor for multi part seems still not working. somehow request fields always empty when intercepting. also retry policy is ignored.

@override
  Future<http.BaseRequest> interceptRequest({required http.BaseRequest request}) async {
    final Map<String, String>? headers = Map.from(request.headers);

    if (request is http.MultipartRequest) {
      print(request.fields); // This will show empty, even though it is populated beforehand.
    }

    return request.copyWith(
      headers: headers,
    );
  }
CodingAleCR commented 2 years ago

I will take a look at it closely and fix it for 2.0.0-beta.3.

Thank you for trying out the library and specially for trying out the beta version 🎊

dexcell commented 2 years ago

I sent pr to fix the problem, tested in my project. working well now.

CodingAleCR commented 2 years ago

I sent pr to fix the problem, tested in my project. working well now.

Thank you! I will Review it during the weekend and if all looks good then create a new prerelease

jsanz1209 commented 2 years ago

Hi @CodingAleCR, I need this functionality in my project, please, when will you accept this pull request?

Thanks in advance.

CodingAleCR commented 2 years ago

Hi @CodingAleCR, I need this functionality in my project, please, when will you accept this pull request?

Thanks in advance.

Hey, @jsanz1209, the PR should be accepted and a new version before the weekend. Sorry for the delay! Happy Holidays!

jsanz1209 commented 2 years ago

Hi @CodingAleCR,

Thanks for your support.

Is this hasn't been uploaded to pub.dev yet, right?

Greetings!

CodingAleCR commented 2 years ago

Hey @jsanz1209,

I completely missed the beta.3 version release, I'm really sorry.

It should be fixed now in a new 2.0.0-beta.4 version. Feel free to try it out, any feedback is always appreciated.

fnicastri commented 2 years ago

Using the beta.4 and trying to implement retry policy + jwt access token on a MultiPart request. Now facing Can't finalize a finalized MultipartRequest 'cause after the first try the files are already finalized. Any suggestion on how to fix this?

Thanks!

CodingAleCR commented 2 years ago

Using the beta.4 and trying to implement retry policy + jwt access token on a MultiPart request. Now facing Can't finalize a finalized MultipartRequest 'cause after the first try the files are already finalized. Any suggestion on how to fix this?

Thanks!

That seems like an issue on the library itself, at least it has been on the past. I'll take a look and get back to you as soon as I can

fnicastri commented 2 years ago

Using the beta.4 and trying to implement retry policy + jwt access token on a MultiPart request. Now facing Can't finalize a finalized MultipartRequest 'cause after the first try the files are already finalized. Any suggestion on how to fix this? Thanks!

That seems like an issue on the library itself, at least it has been on the past. I'll take a look and get back to you as soon as I can

Thanks!

CodingAleCR commented 2 years ago

Hi just an update, the library does have issues on this front. It seems we need to copy all MultipartFiles. Otherwise the upload retry won't work because each MultipartFile is a stream and has already been closed when the MultipartRequest is closed (for example when the request fails).

Now this type of issues should only be appearing on "retried" requests. If everything is fine and the request does not need retrying then the library should work as expected ;]

fnicastri commented 2 years ago

yep, of course we should find a way to make it work on retried calls too. For now I'm not using it with multipart, but I'm managing them externally.

thanks

justincbeck commented 1 year ago

I wish I could still set the retry policy independent of the constructor.

CodingAleCR commented 1 year ago

I wish I could still set the retry policy independent of the constructor.

Like having a global retry policy?