onRequest method
Called when the request is about to be sent.
Implementation
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
cookieJar.loadForRequest(options.uri).then((cookies) {
final previousCookies =
options.headers[HttpHeaders.cookieHeader] as String?;
final newCookies = getCookies([
...?previousCookies
?.split(';')
.where((e) => e.isNotEmpty)
.map((c) => Cookie.fromSetCookieValue(c)),
...cookies,
]);
options.headers[HttpHeaders.cookieHeader] =
newCookies.isNotEmpty ? newCookies : null;
handler.next(options);
}).catchError((dynamic e, StackTrace s) {
final err = DioException(
requestOptions: options,
error: e,
stackTrace: s,
);
handler.reject(err, true);
});
}