use aho_corasick::AhoCorasick;
use once_cell::sync::Lazy;
static BLOCK_AC: Lazy<AhoCorasick> = Lazy::new(|| {
AhoCorasick::builder()
.ascii_case_insensitive(true)
.build(BLOCK_INDICATORS)
.expect("block indicators are valid AC patterns")
});
const BLOCK_INDICATORS: &[&str] = &[
"access denied",
"blocked",
"forbidden",
"captcha",
"challenge",
"request denied",
"security policy",
"not acceptable",
"rate limit",
"too many requests",
"waf",
"firewall",
"request blocked",
];
#[must_use]
pub fn is_blocked_response(status: u16, body: &[u8]) -> bool {
if matches!(
status,
401 | 403 | 405 | 406 | 407 | 429 | 499 | 502 | 503 | 504 | 520..=526
) {
return true;
}
let window = &body[..body.len().min(4096)];
BLOCK_AC.is_match(window)
}