http_interceptor icon indicating copy to clipboard operation
http_interceptor copied to clipboard

Ability to edit Response body in interceptor

Open mohamed155 opened this issue 1 year ago • 6 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<RequestData> interceptRequest({required RequestData data}) async { return data; }

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

mohamed155 avatar Apr 19 '23 03:04 mohamed155

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.

CodingAleCR avatar May 01 '23 21:05 CodingAleCR

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

Manasmd avatar May 10 '23 11:05 Manasmd

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.

CodingAleCR avatar Jul 08 '23 05:07 CodingAleCR

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[bot] avatar Sep 17 '23 00:09 stale[bot]

Hi @CodingAleCR، i'm using the version 1.0.2

mohamed155 avatar Oct 24 '23 14:10 mohamed155

@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.

CodingAleCR avatar Jul 11 '24 15:07 CodingAleCR