generated from ElnuDev/rust-project
parent
7c043e8357
commit
ef562fe656
@ -0,0 +1,21 @@
|
||||
use actix_web::{http::header, HttpRequest};
|
||||
|
||||
pub fn is_human(request: &HttpRequest) -> bool {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
|
||||
const HUMANS: &[&str] = &[
|
||||
"Firefox", "Chrome", // Chrome and Chromium browsers
|
||||
"Opera", // Old Presto-based Opera
|
||||
"Mobile", // Safari
|
||||
"Trident", // Internet Explorer
|
||||
];
|
||||
request
|
||||
.headers()
|
||||
.get(header::USER_AGENT)
|
||||
.and_then(|header| header.to_str().ok())
|
||||
.map(|ua| {
|
||||
HUMANS
|
||||
.iter()
|
||||
.any(|&human| ua.contains(human))
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
@ -1,21 +1,6 @@
|
||||
use actix_web::{http::header, HttpRequest};
|
||||
pub mod error;
|
||||
|
||||
pub fn is_human(request: &HttpRequest) -> bool {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
|
||||
const HUMANS: &[&str] = &[
|
||||
"Firefox", "Chrome", // Chrome and Chromium browsers
|
||||
"Opera", // Old Presto-based Opera
|
||||
"Mobile", // Safari
|
||||
"Trident", // Internet Explorer
|
||||
];
|
||||
request
|
||||
.headers()
|
||||
.get(header::USER_AGENT)
|
||||
.and_then(|header| header.to_str().ok())
|
||||
.map(|ua| {
|
||||
HUMANS
|
||||
.iter()
|
||||
.any(|&human| ua.contains(human))
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
#[cfg(feature = "nothuman")]
|
||||
mod is_human;
|
||||
#[cfg(feature = "nothuman")]
|
||||
pub use is_human::is_human;
|
||||
|
Loading…
Reference in new issue