add Response::remote_addr() method

The new `remote_addr` method returns an `Option<SocketAddr>`, which is
`Some` if the underlying transport uses socket addresses.

Closes #373
This commit is contained in:
Sean McArthur
2018-10-26 14:23:21 -07:00
parent c91f37babf
commit 478ef9bf15
4 changed files with 41 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
use std::mem;
use std::fmt;
use std::io::{self, Read};
use std::net::SocketAddr;
use std::time::Duration;
use std::borrow::Cow;
@@ -61,6 +62,22 @@ impl Response {
self.inner.url()
}
/// Get the remote address used to get this `Response`.
///
/// # Example
///
/// ```rust
/// # fn run() -> Result<(), Box<::std::error::Error>> {
/// let resp = reqwest::get("http://httpbin.org/redirect/1")?;
/// println!("httpbin.org address: {:?}", resp.remote_addr());
/// # Ok(())
/// # }
/// ```
pub fn remote_addr(&self) -> Option<SocketAddr> {
self.inner.remote_addr()
}
/// Get the `StatusCode` of this `Response`.
///
/// # Examples