CodingAleCR / http_interceptor

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

Modified params are not reflecting in api call. #19

Closed periyasamyshanmugam closed 4 years ago

periyasamyshanmugam commented 4 years ago

Hello, I am modifying my request url params in my interceptor but the modified params are not reflecting in my api call.

data.params["xyz"] = "mytoken"; this is how I am modifying the request params. Please, help me with this. Thanks.

CodingAleCR commented 4 years ago

Hi, I am currently checking this out since it was reported by a couple of people as well. This is definitely a bug and will fix ASAP. Thanks for writing :)

CodingAleCR commented 4 years ago

Hi, @periyasamyshanmugam I've being trying to reproduce your problem but can't seem to get it. Could you post the piece of code where you are using either the HttpClientWithInterceptor or the HttpWithInterceptor to see if there is something wrong with the way you are using it?

periyasamyshanmugam commented 4 years ago

Hi, @CodingAleCR First of all sorry for late reply.

Simply I want to modify my url params using below code.

Future<RequestData> interceptRequest({RequestData data}) async {
    try {
      data.params["tokenString"] = "XXXXXXXXXXX";
    } catch (err) {
      print(err);
    }
    return data;
  }

This is my code where I am trying to add token string to my request params. But it is not reflecting in api request url.

Thanks.

CodingAleCR commented 4 years ago

No worries, here to help.

I understand that part, but I can't find any issues with the library. Are you using any of the options shown as followed for doing your request:

Using interceptors with Client

Client client = HttpClientWithInterceptor.build(interceptors: [
    YourInterceptor(),
]);

Using interceptors without Client

var response = await HttpWithInterceptor
      .build(interceptors: [YourInterceptor()])
      .get("<change-with-your-url>");
periyasamyshanmugam commented 4 years ago

@CodingAleCR Yes I am using without client.

HttpWithInterceptor.build(
        interceptors: [TokenInterceptor(context)]).post(url, body: filter)

Like this. Is anything wrong in this?

CodingAleCR commented 4 years ago

There doesn't seem to be anything wrong with. the code, I will keep making tests to see if I am able to reproduce it. Is your context defined properly for your interceptor? Meaning, does it get assigned properly?

periyasamyshanmugam commented 4 years ago

@CodingAleCR Yes I have defined and assigned my context properly.

CodingAleCR commented 4 years ago

Do you think maybe we could hop on a call and troubleshoot this problem? I am unable to reproduce it and I really want to help out the user's of the library. Cheers!

12Hemang commented 4 years ago

Hi There, i am facing same issue, on 401 API get called for token refresh , and new token get saved in shared preference (same printed in log also), but after that the old request get called without token. Is there is any way that i can modify request with new header before call in shouldAttemptRetryOnResponse method..??

CodingAleCR commented 4 years ago

Hi, what version of the library are you currently using? There was a bug that did not refresh interception after the first call and I'd like to verify if that is the issue you are having or if it's a different one. Thanks for writing!

12Hemang commented 4 years ago

Hi thank you for quick response , its really appreciable
Currently i m using http_interceptor: ^0.3.1 , and yes once after updating token on 401 the next call is not updated with latest data

12Hemang commented 4 years ago

Hi,Thanks i updated version http_interceptor: ^0.3.2 and issue resolved

CodingAleCR commented 4 years ago

I'm glad to hear that it was the issue I fixed recently 🎉 thanks for using the library and hopefully it helps you out a lot.