InterceptorTimeout class

An interceptor that enforces a physical connection timeout on HTTP requests using Abortable.

When the timeout duration elapses before the response arrives:

  • The underlying socket/HTTP connection is aborted immediately.
  • A warning is recorded to logger if provided.
  • An onTimeout callback is invoked if provided.

Example:

final client = interceptedClient(
  interceptors: [
    InterceptorTimeout(
      Duration(seconds: 10),
      logger: logger,
      onTimeout: (request) {
        print('Request timed out: ${request.method} ${request.url}');
      },
    ),
  ],
);
Inheritance

Constructors

InterceptorTimeout(Duration timeout, {Logger? logger, TimeoutCallback? onTimeout})

Properties

hashCode → int
The hash code for this object.
no setterinherited
logger → Logger?
Optional logger to record timeout abort warnings.
final
onTimeout → TimeoutCallback?
Optional callback invoked when a request times out and is aborted.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
timeout → Duration
The maximum duration to wait for a request/response before aborting.
final

Methods

interceptRequest({required BaseRequest request}) → Future<BaseRequest>
override
interceptResponse({required BaseResponse response}) → Future<BaseResponse>
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
shouldInterceptRequest() → FutureOr<bool>
inherited
shouldInterceptResponse() → FutureOr<bool>
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited