HttpCaptureScope class
Scope managing the capture lifecycle of an individual HTTP request-response exchange.
Guaranteed to be safe, idempotent, and non-intrusive:
- Errors during capture are swallowed and never escape to host applications.
- Once settled via complete or fail, subsequent completion calls are no-ops.
- Response streams can be bound via bindResponseStream for automatic chunk teeing and throttling.
Constructors
- HttpCaptureScope({required HttpTrafficCollector collector, required HttpRequestContext? context})
-
Creates an active HttpCaptureScope associated with
context. - HttpCaptureScope.inactive([HttpTrafficCollector? collector])
-
Inactive scope used when capture is disabled or initiation failed.
factory
Properties
- collector → HttpTrafficCollector
-
The collector coordinating storage and simulation.
final
- context → HttpRequestContext?
-
The immutable request context.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String?
-
Unique identifier of the tracked request, if active.
no setter
- isActive → bool
-
Whether this scope is actively tracking an ongoing request.
no setter
- isSettled → bool
-
Whether this exchange has completed or failed.
no setter
- method → String?
-
HTTP method of the request, if active.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- startedAt → DateTime?
-
Wall-clock initiation timestamp, if active.
no setter
- uri → Uri?
-
Target URI of the request, if active.
no setter
Methods
-
amendRequest(
{String? method, Uri? uri, Map< String, String> ? headers, Uint8List? bodyBytes, String? contentType}) → void - Amends initial request parameters if modified downstream by an interceptor.
-
bindResponseStream(
Stream< List< responseStream, {required int statusCode, Map<int> >String, String> ? headers, String? contentType}) → Stream<List< int> > -
Binds this scope to a streaming response, capturing chunks up to
collector.maxBodyBytes, applying simulation delays if enabled, and automatically settling with complete or fail. -
complete(
{required int statusCode, Map< String, String> ? headers, Uint8List? bodyBytes, int? responseSizeBytes, String? contentType, int? durationMs, bool? responseTruncatedAtStorage}) → Future<void> - Records a completed HTTP response. Safe and idempotent.
-
fail(
Object error, {StackTrace? stackTrace, String? errorType, String? errorMessage, int? statusCode, Map< String, String> ? responseHeaders, Uint8List? responseBodyBytes, int? responseSizeBytes, int? durationMs, bool? responseTruncatedAtStorage}) → void - Records a failed HTTP request (transport error, simulation failure, or cancellation). Safe and idempotent.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited