onRequest method

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

Called when the request is about to be sent.

Implementation

@override
void onRequest(options, handler) async {
  OnRequestHandler? onRequestHandler = HttpService.to.onRequestHandler;
  if (onRequestHandler != null) {
    if (await onRequestHandler(options, handler)) {
      return;
    }
  }

  String? authorization = HttpService.to.authorization;
  if (authorization.isNotEmptyOrNull) {
    if (!options.headers.containsKey('Authorization')) {
      options.headers.addAll({'Authorization': authorization});
    }
  }
  handler.next(options);
}