mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 20:47:01 +01:00
Fix ip addr parse (#1729)
This commit is contained in:
parent
18fe86db26
commit
38f8ab2f99
|
@ -186,12 +186,12 @@ impl RequestExtensions for tide::Request<AppState> {
|
||||||
/// Returns the remote address of the client, based on if you've got trust_x_forward_for set in config.
|
/// Returns the remote address of the client, based on if you've got trust_x_forward_for set in config.
|
||||||
fn get_remote_addr(&self) -> Option<IpAddr> {
|
fn get_remote_addr(&self) -> Option<IpAddr> {
|
||||||
if self.state().trust_x_forward_for {
|
if self.state().trust_x_forward_for {
|
||||||
// split the socket address off if we've got one, then parse it as an `IpAddr`
|
|
||||||
// xff headers don't have a port, but if we're going direct you might get one
|
// xff headers don't have a port, but if we're going direct you might get one
|
||||||
let res = self
|
let res = self.remote().and_then(|ip| {
|
||||||
.remote()
|
ip.parse::<IpAddr>()
|
||||||
.map(|addr| addr.split(':').next().unwrap_or(addr))
|
.ok()
|
||||||
.and_then(|ip| ip.parse::<IpAddr>().ok());
|
.or_else(|| ip.parse::<SocketAddr>().map(|s_ad| s_ad.ip()).ok())
|
||||||
|
});
|
||||||
debug!("Trusting XFF, using remote src_ip={:?}", res);
|
debug!("Trusting XFF, using remote src_ip={:?}", res);
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue