extract method
Produces the value, or the rejection that stops the handler.
Implementation
@override
Future<Result<String, Rejection>> extract(Request request) async {
final fromHeader = RequestParts.of(request).headers[header.toLowerCase()];
if (fromHeader != null && fromHeader.isNotEmpty) return Ok(fromHeader);
if (allowQuery) {
final fromQuery = request.url.queryParameters[query];
if (fromQuery != null && fromQuery.isNotEmpty) return Ok(fromQuery);
}
return Err(
Rejection.unauthorized(
'expected an API key in the $header header',
challenge: 'ApiKey',
),
);
}