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

add ConnectionInfo tests

This commit is contained in:
Nikolay Kim
2017-12-05 21:38:52 -08:00
parent c3de32c3b3
commit d7e65b6212
6 changed files with 114 additions and 42 deletions

View File

@@ -140,12 +140,27 @@ impl<S> HttpRequest<S> {
&self.0.headers
}
#[cfg(test)]
pub fn headers_mut(&mut self) -> &mut HeaderMap {
&mut self.as_mut().headers
}
/// The target path of this Request.
#[inline]
pub fn path(&self) -> &str {
self.0.uri.path()
}
/// Get previously loaded *ConnectionInfo*.
#[inline]
pub fn connection_info(&self) -> Option<&ConnectionInfo> {
if self.0.info.is_none() {
None
} else {
self.0.info.as_ref()
}
}
/// Load *ConnectionInfo* for currect request.
#[inline]
pub fn load_connection_info(&mut self) -> &ConnectionInfo {
@@ -157,19 +172,12 @@ impl<S> HttpRequest<S> {
self.0.info.as_ref().unwrap()
}
/// Remote IP of client initiated HTTP request.
///
/// The IP is resolved through the following headers, in this order:
///
/// - Forwarded
/// - X-Forwarded-For
/// - peername of opened socket
#[inline]
pub fn remote(&self) -> Option<&SocketAddr> {
pub fn peer_addr(&self) -> Option<&SocketAddr> {
self.0.addr.as_ref()
}
pub(crate) fn set_remove_addr(&mut self, addr: Option<SocketAddr>) {
pub(crate) fn set_peer_addr(&mut self, addr: Option<SocketAddr>) {
self.as_mut().addr = addr
}