onRequest method
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);
}