1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 00:50:20 +02:00

Add .peer_addr() #744

This commit is contained in:
Nikolay Kim
2019-04-16 10:11:38 -07:00
parent eb4f6b74fb
commit 420d3064c5
5 changed files with 48 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
use std::cell::{Ref, RefMut};
use std::fmt;
use std::{fmt, net};
use actix_http::body::{Body, MessageBody, ResponseBody};
use actix_http::http::{HeaderMap, Method, StatusCode, Uri, Version};
@@ -12,6 +12,7 @@ use futures::future::{ok, FutureResult, IntoFuture};
use crate::config::{AppConfig, AppService};
use crate::data::Data;
use crate::info::ConnectionInfo;
use crate::request::HttpRequest;
pub trait HttpServiceFactory {
@@ -134,6 +135,23 @@ impl ServiceRequest {
}
}
/// Peer socket address
///
/// Peer address is actual socket address, if proxy is used in front of
/// actix http server, then peer address would be address of this proxy.
///
/// To get client connection information `ConnectionInfo` should be used.
#[inline]
pub fn peer_addr(&self) -> Option<net::SocketAddr> {
self.head().peer_addr
}
/// Get *ConnectionInfo* for the current request.
#[inline]
pub fn connection_info(&self) -> Ref<ConnectionInfo> {
ConnectionInfo::get(self.head(), &*self.app_config())
}
/// Get a reference to the Path parameters.
///
/// Params is a container for url parameters.