checkRequest method
Implementation
void checkRequest(HttpRequest req, [Function? fn]) {
var origin = req.headers.value('origin') ?? req.headers.value('referer');
if (origin == null || origin.isEmpty) {
origin = '*';
}
if (origin.isNotEmpty && _origins is Function) {
_origins(origin, fn);
return;
}
if (_origins.contains('*:*')) {
fn!(null, true);
return;
}
if (origin.isNotEmpty) {
try {
var parts = Uri.parse(origin);
var port = parts.port;
var ok = _origins.indexOf(parts.host + ':' + port.toString()) >= 0 ||
_origins.indexOf(parts.host + ':*') >= 0 ||
_origins.indexOf('*:' + port.toString()) >= 0;
fn!(null, ok);
return;
} catch (ex) {
//
}
}
fn!(null, false);
}