CodingAleCR / http_interceptor

A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can it be used with MultipartRequest?

riskiadi opened this issue · comments

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)

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

#98

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)

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.

commented

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,
    );
  }

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 🎊

commented

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

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

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

Thanks in advance.

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!

Hi @CodingAleCR,

Thanks for your support.

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

Greetings!

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.

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!

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

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!

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 ;]

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

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

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

Like having a global retry policy?