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
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
final authInfo =
getAuthInfo(options, (secure) => secure['type'] == 'apiKey');
for (final info in authInfo) {
final String authName = info['name']!;
final apiKey = apiKeys[authName];
if (apiKey == null) {
continue;
}
final String authKeyName = info['keyName']!;
final String authWhere = info['where']!;
if (authWhere == 'query') {
options.queryParameters[authKeyName] = apiKey;
} else {
options.headers[authKeyName] = apiKey;
}
}
super.onRequest(options, handler);
}