adding log to unauthorized, and error log when err accepting conn
This commit is contained in:
@@ -31,13 +31,16 @@ impl Server {
|
||||
|
||||
let handler = Arc::new(handler);
|
||||
loop {
|
||||
let listener_res = listener.accept().await;
|
||||
if listener_res.is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let (tcp, client_addr) = listener_res.unwrap();
|
||||
let client_ip = client_addr.ip();
|
||||
let (tcp, client_addr) = match listener.accept().await {
|
||||
Ok(conn) => conn,
|
||||
Err(error) => {
|
||||
error!(
|
||||
error = error.to_string().as_str();
|
||||
"Failed to accept connection"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let io = TokioIo::new(tcp);
|
||||
|
||||
let config = Arc::clone(&self.config);
|
||||
@@ -52,9 +55,16 @@ impl Server {
|
||||
let handler = Arc::clone(&handler);
|
||||
|
||||
async move {
|
||||
if !config.is_ip_authorized(&client_ip)
|
||||
if !config.is_ip_authorized(&client_addr.ip())
|
||||
|| !config.is_req_authorized(&req)
|
||||
{
|
||||
if config.log_unauthorized {
|
||||
error!(tag = "ban",
|
||||
ip = client_addr.ip().to_string().as_str();
|
||||
"Unauthorized"
|
||||
);
|
||||
}
|
||||
|
||||
Responder::unathorized()
|
||||
} else {
|
||||
handler(req).await
|
||||
|
||||
Reference in New Issue
Block a user