onRequest method
The callback will be executed before the request is initiated.
If you want to continue the request, call handler.next
.
If you want to complete the request with some custom data,
you can resolve a Response
object with handler.resolve
.
If you want to complete the request with an error message,
you can reject a DioError
object with handler.reject
.
Implementation
@override
Future onRequest(
RequestOptions options, RequestInterceptorHandler handler) async {
try {
final metric = FirebasePerformance.instance.newHttpMetric(
options.uri.normalized(),
options.method.asHttpMethod()!,
);
final requestKey = options.extra.hashCode;
_map[requestKey] = metric;
final requestContentLength = requestContentLengthMethod(options);
await metric.start();
if (requestContentLength != null) {
metric.requestPayloadSize = requestContentLength;
}
} catch (_) {}
return super.onRequest(options, handler);
}