beforeRequest method

  1. @override
Future<HttpClientRequest?> beforeRequest(
  1. HttpClientRequest request
)
override

@params kraken: The Kraken widget that is requesting the resource. request: HttpClientRequest that containing the detail of the request. @return newRequest: A HttpClientRequest containing the response information or null if the kraken should load the resource itself.

Implementation

@override
Future<HttpClientRequest?> beforeRequest(HttpClientRequest request) {
  sendEventToFrontend(NetworkRequestWillBeSentEvent(
    requestId: _getRequestId(request),
    loaderId: devtoolsService.controller!.view.contextId.toString(),
    requestMethod: request.method,
    url: request.uri.toString(),
    headers: _getHttpHeaders(request.headers),
    timestamp: (DateTime.now().millisecondsSinceEpoch - _initialTimestamp) ~/ 1000,
  ));
  HttpClientInterceptor? customHttpClientInterceptor = _customHttpClientInterceptor;
  if (customHttpClientInterceptor != null) {
    return customHttpClientInterceptor.beforeRequest(request);
  } else {
    return Future.value(null);
  }
}