Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.0-beta.5

- ✨  Added: Support for `onRequestTimeout` when setting up `requestTimeout` on the interceptor.

## 2.0.0-beta.4

- ❗️🛠  Changed: `shouldAttemptRetryOnException` will now also pass the `BaseRequest`.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ http_interceptor: ^1.0.1
- 🖋 Supports self-signed certificates (except on Flutter Web).
- 🍦 Compatible with vanilla Dart projects or Flutter projects.
- 🎉 Null-safety.
- ⏲ Timeout configuration with duration and timeout functions.

## Usage

Expand Down
12 changes: 11 additions & 1 deletion lib/http/intercepted_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:http_interceptor/models/models.dart';
import 'http_methods.dart';
import 'interceptor_contract.dart';

typedef TimeoutCallback = FutureOr<StreamedResponse> Function();

/// Class to be used by the user to set up a new `http.Client` with interceptor
/// support.
///
Expand Down Expand Up @@ -44,6 +46,9 @@ class InterceptedClient extends BaseClient {
/// Maximum duration of a request.
final Duration? requestTimeout;

/// Request timeout handler
TimeoutCallback? onRequestTimeout;

/// A policy that defines whether a request or response should trigger a
/// retry. This is useful for implementing JWT token expiration
final RetryPolicy? retryPolicy;
Expand All @@ -54,6 +59,7 @@ class InterceptedClient extends BaseClient {
InterceptedClient._internal({
required this.interceptors,
this.requestTimeout,
this.onRequestTimeout,
this.retryPolicy,
Client? client,
}) : _inner = client ?? Client();
Expand All @@ -78,12 +84,14 @@ class InterceptedClient extends BaseClient {
factory InterceptedClient.build({
required List<InterceptorContract> interceptors,
Duration? requestTimeout,
TimeoutCallback? onRequestTimeout,
RetryPolicy? retryPolicy,
Client? client,
}) =>
InterceptedClient._internal(
interceptors: interceptors,
requestTimeout: requestTimeout,
onRequestTimeout: onRequestTimeout,
retryPolicy: retryPolicy,
client: client,
);
Expand Down Expand Up @@ -264,7 +272,9 @@ class InterceptedClient extends BaseClient {

var stream = requestTimeout == null
? await _inner.send(interceptedRequest)
: await _inner.send(interceptedRequest).timeout(requestTimeout!);
: await _inner
.send(interceptedRequest)
.timeout(requestTimeout!, onTimeout: onRequestTimeout);

response =
request is Request ? await Response.fromStream(stream) : stream;
Expand Down
7 changes: 7 additions & 0 deletions lib/http/intercepted_http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class InterceptedHttp {
/// Maximum duration of a request.
final Duration? requestTimeout;

/// Request timeout handler
TimeoutCallback? onRequestTimeout;

/// A policy that defines whether a request or response should trigger a
/// retry. This is useful for implementing JWT token expiration
final RetryPolicy? retryPolicy;
Expand All @@ -54,6 +57,7 @@ class InterceptedHttp {
InterceptedHttp._internal({
required this.interceptors,
this.requestTimeout,
this.onRequestTimeout,
this.retryPolicy,
this.client,
});
Expand All @@ -79,12 +83,14 @@ class InterceptedHttp {
factory InterceptedHttp.build({
required List<InterceptorContract> interceptors,
Duration? requestTimeout,
TimeoutCallback? onRequestTimeout,
RetryPolicy? retryPolicy,
Client? client,
}) =>
InterceptedHttp._internal(
interceptors: interceptors,
requestTimeout: requestTimeout,
onRequestTimeout: onRequestTimeout,
retryPolicy: retryPolicy,
client: client,
);
Expand Down Expand Up @@ -222,6 +228,7 @@ class InterceptedHttp {
final client = InterceptedClient.build(
interceptors: interceptors,
requestTimeout: requestTimeout,
onRequestTimeout: onRequestTimeout,
retryPolicy: retryPolicy,
client: this.client,
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: http_interceptor
description: A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.
version: 2.0.0-beta.4
version: 2.0.0-beta.5
homepage: https://github.com/CodingAleCR/http_interceptor
issue_tracker: https://github.com/CodingAleCR/http_interceptor/issues
repository: https://github.com/CodingAleCR/http_interceptor
Expand Down