Ability to edit Response body in interceptor
mohamed155 opened this issue · comments
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;
}
}
`
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;
}