Skip to content
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

Ability to edit Response body in interceptor #124

Open
mohamed155 opened this issue Apr 19, 2023 · 6 comments
Open

Ability to edit Response body in interceptor #124

mohamed155 opened this issue Apr 19, 2023 · 6 comments
Assignees

Comments

@mohamed155
Copy link

mohamed155 commented Apr 19, 2023

Since the HTTP Response body is a getter, we need a way to modify the Response body after it's fetched.

For example:

`
class APIInterceptors extends InterceptorContract {
@OverRide
Future interceptRequest({required RequestData data}) async {
return data;
}

@OverRide
Future interceptResponse({required ResponseData data}) async {
data.body = someMethodMakeSomeModifications(data.body);
return data;
}
}
`

@CodingAleCR
Copy link
Owner

This is a great idea. I'm looking into it, as it would enable body parsing, but it's a complex operation and there may be some features that get affected and some even might get deprecated.

@Manasmd
Copy link

Manasmd commented May 10, 2023

Yes, this would be great!

I actually tried overriding the response body, however, it's not working:


    @override
     Future<ResponseData> interceptResponse({required ResponseData data}) async {

    ResponseData newData = data;

    newData.body = '{"test":"test"}';

    print('response data has been modified...');
    print(newData.body);
    return newData;
  }

@CodingAleCR
Copy link
Owner

Sorry, what version of the package are you using @mohamed155 ?

I made some tests for this in the beta releases and just want to double-check if the tests are not covering this scenario for some reason.

@stale
Copy link

stale bot commented Sep 17, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Sep 17, 2023
@mohamed155
Copy link
Author

Hi @CodingAleCR، i'm using the version 1.0.2

@CodingAleCR
Copy link
Owner

@mohamed155 There were a couple of fixes included into beta versions of 2.0.0 that might have not been replicated to 1.x versions. In any case there's a stable version 2.x that could fix your issues and improve a bunch of other things.

@stale stale bot removed the wontfix This will not be worked on label Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants