onRequest method

  1. @override
void onRequest(
  1. RequestOptions options,
  2. RequestInterceptorHandler handler
)

Called when the request is about to be sent.

Implementation

@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
  dynamic serializedBody;
  serializedBody = options.data;
  if (options.data != null) {
    if (options.data is String) {
      serializedBody = options.data;
    } else {
      try {
        serializedBody = json.encode(options.data);
      } catch (e) {
        serializedBody = options.data.toString();
      }
    }
  }
  final requestKey = _core.processRequest(
    method: options.method,
    uri: options.uri,
    headers: options.headers,
    body: serializedBody,
  );

  if (requestKey != null) {
    options.headers['X-Vigil-Request-Key'] = requestKey;
  }

  handler.next(options);
}