Skip to content

Commit 4b36b3c

Browse files
committed
feat: pass request to conditional methods
1 parent 3cd905a commit 4b36b3c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/http/intercepted_client.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ class InterceptedClient extends BaseClient {
316316
Future<BaseRequest> _interceptRequest(BaseRequest request) async {
317317
BaseRequest interceptedRequest = request.copyWith();
318318
for (InterceptorContract interceptor in interceptors) {
319-
if (await interceptor.shouldInterceptRequest()) {
319+
if (await interceptor.shouldInterceptRequest(
320+
request: interceptedRequest)) {
320321
interceptedRequest = await interceptor.interceptRequest(
321322
request: interceptedRequest,
322323
);
@@ -330,7 +331,8 @@ class InterceptedClient extends BaseClient {
330331
Future<BaseResponse> _interceptResponse(BaseResponse response) async {
331332
BaseResponse interceptedResponse = response;
332333
for (InterceptorContract interceptor in interceptors) {
333-
if (await interceptor.shouldInterceptResponse()) {
334+
if (await interceptor.shouldInterceptResponse(
335+
response: interceptedResponse)) {
334336
interceptedResponse = await interceptor.interceptResponse(
335337
response: interceptedResponse,
336338
);

lib/models/interceptor_contract.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import 'package:http/http.dart';
2828
///}
2929
///```
3030
abstract class InterceptorContract {
31-
FutureOr<bool> shouldInterceptRequest() => true;
31+
FutureOr<bool> shouldInterceptRequest({required BaseRequest request}) => true;
3232

3333
FutureOr<BaseRequest> interceptRequest({required BaseRequest request});
3434

35-
FutureOr<bool> shouldInterceptResponse() => true;
35+
FutureOr<bool> shouldInterceptResponse({required BaseResponse response}) => true;
3636

3737
FutureOr<BaseResponse> interceptResponse({required BaseResponse response});
3838
}

0 commit comments

Comments
 (0)