All checks were successful
continuous-integration/drone/push Build is passing
31 lines
722 B
Rust
31 lines
722 B
Rust
use std::net::IpAddr;
|
|
|
|
use actix_web::dev::Payload;
|
|
use actix_web::{Error, FromRequest, HttpRequest};
|
|
use futures_util::future::{ready, Ready};
|
|
|
|
use crate::data::app_config::AppConfig;
|
|
use crate::utils::network_utils::get_remote_ip;
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
|
pub struct RemoteIP(pub IpAddr);
|
|
|
|
impl From<RemoteIP> for IpAddr {
|
|
fn from(i: RemoteIP) -> Self {
|
|
i.0
|
|
}
|
|
}
|
|
|
|
impl FromRequest for RemoteIP {
|
|
type Error = Error;
|
|
type Future = Ready<Result<Self, Error>>;
|
|
|
|
#[inline]
|
|
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
|
ready(Ok(RemoteIP(get_remote_ip(
|
|
req,
|
|
AppConfig::get().proxy_ip.as_deref(),
|
|
))))
|
|
}
|
|
}
|