http_interceptor
http_interceptor copied to clipboard
Ability to edit Response body in interceptor
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<RequestData> interceptRequest({required RequestData data}) async { return data; }
@override Future<ResponseData> interceptResponse({required ResponseData data}) async { data.body = someMethodMakeSomeModifications(data.body); return data; } } `
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.
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;
}
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.
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.
Hi @CodingAleCR، i'm using the version 1.0.2
@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.