main
Elnu 1 year ago
parent 18f64358f0
commit 412ca4e538

@ -1,4 +1,7 @@
use utils::{error::{Error, Result}, is_human}; use utils::{
error::{Error, Result},
is_human,
};
use actix_web::{get, http::header, App, HttpRequest, HttpResponse, HttpServer, Responder}; use actix_web::{get, http::header, App, HttpRequest, HttpResponse, HttpServer, Responder};
use clap::Parser; use clap::Parser;

@ -11,7 +11,9 @@ pub type Result<T> = std::result::Result<T, Error>;
pub enum Error { pub enum Error {
Reqwest(reqwest::Error), Reqwest(reqwest::Error),
#[cfg(feature = "nothuman")] #[cfg(feature = "nothuman")]
NotHuman { target: String }, NotHuman {
target: String,
},
} }
impl Display for Error { impl Display for Error {
@ -45,4 +47,3 @@ impl ResponseError for Error {
}) })
} }
} }

@ -12,10 +12,6 @@ pub fn is_human(request: &HttpRequest) -> bool {
.headers() .headers()
.get(header::USER_AGENT) .get(header::USER_AGENT)
.and_then(|header| header.to_str().ok()) .and_then(|header| header.to_str().ok())
.map(|ua| { .map(|ua| HUMANS.iter().any(|&human| ua.contains(human)))
HUMANS
.iter()
.any(|&human| ua.contains(human))
})
.unwrap_or(false) .unwrap_or(false)
} }
Loading…
Cancel
Save