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) {
  List<int> data = List<int>.from((request as ProxyHttpClientRequest).data);

  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,
    data: data,
  ));

  Map<String, List<String>> extraHeaders = {
    ':authority': [request.uri.authority],
    ':method': [request.method],
    ':path': [request.uri.path],
    ':scheme': [request.uri.scheme],
  };
  sendEventToFrontend(NetworkRequestWillBeSendExtraInfo(
        associatedCookies: [],
        clientSecurityState: {
        'initiatorIsSecureContext': true,
        'initiatorIPAddressSpace': 'Local',
        'privateNetworkRequestPolicy': 'PreflightWarn'
      },
      connectTiming: {
        'requestTime': 100000
      },
      headers: {
        ..._getHttpHeaders(request.headers),
        ...extraHeaders
      },
      siteHasCookieInOtherPartition: false,
      requestId: _getRequestId(request)));
  HttpClientInterceptor? customHttpClientInterceptor = _customHttpClientInterceptor;
  if (customHttpClientInterceptor != null) {
    return customHttpClientInterceptor.beforeRequest(request);
  } else {
    return Future.value(null);
  }
}