expose local_addr() from Response
This commit is contained in:
committed by
Martin Algesten
parent
ec663fad45
commit
bfb0ef16e1
26
src/agent.rs
26
src/agent.rs
@@ -78,6 +78,7 @@ pub(crate) struct AgentConfig {
|
|||||||
pub redirect_auth_headers: RedirectAuthHeaders,
|
pub redirect_auth_headers: RedirectAuthHeaders,
|
||||||
pub user_agent: String,
|
pub user_agent: String,
|
||||||
pub tls_config: TlsConfig,
|
pub tls_config: TlsConfig,
|
||||||
|
pub get_local_addr: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Agents keep state between requests.
|
/// Agents keep state between requests.
|
||||||
@@ -262,6 +263,7 @@ impl AgentBuilder {
|
|||||||
redirect_auth_headers: RedirectAuthHeaders::Never,
|
redirect_auth_headers: RedirectAuthHeaders::Never,
|
||||||
user_agent: format!("ureq/{}", env!("CARGO_PKG_VERSION")),
|
user_agent: format!("ureq/{}", env!("CARGO_PKG_VERSION")),
|
||||||
tls_config: TlsConfig(crate::default_tls_config()),
|
tls_config: TlsConfig(crate::default_tls_config()),
|
||||||
|
get_local_addr: false,
|
||||||
},
|
},
|
||||||
max_idle_connections: DEFAULT_MAX_IDLE_CONNECTIONS,
|
max_idle_connections: DEFAULT_MAX_IDLE_CONNECTIONS,
|
||||||
max_idle_connections_per_host: DEFAULT_MAX_IDLE_CONNECTIONS_PER_HOST,
|
max_idle_connections_per_host: DEFAULT_MAX_IDLE_CONNECTIONS_PER_HOST,
|
||||||
@@ -620,6 +622,30 @@ impl AgentBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether local_addr will be read from the tcp socket.
|
||||||
|
///
|
||||||
|
/// local_addr is the address from which the client sends the request.
|
||||||
|
/// Reading it invokes a syscall, therefore it is disabled by default.
|
||||||
|
///
|
||||||
|
/// Defaults to false.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # fn main() -> Result<(), ureq::Error> {
|
||||||
|
/// # use std::net::SocketAddr;
|
||||||
|
/// # ureq::is_test(true);
|
||||||
|
/// let agent = ureq::builder()
|
||||||
|
/// .get_local_addr(true)
|
||||||
|
/// .build();
|
||||||
|
/// let response = agent.get("http://httpbin.org/get").call()?;
|
||||||
|
/// assert!(response.local_addr().is_some());
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
pub fn get_local_addr(mut self, get_local_addr: bool) -> Self {
|
||||||
|
self.config.get_local_addr = get_local_addr;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Provide the cookie store to be used for all requests using this agent.
|
/// Provide the cookie store to be used for all requests using this agent.
|
||||||
///
|
///
|
||||||
/// This is useful in two cases. First when there is a need to persist cookies
|
/// This is useful in two cases. First when there is a need to persist cookies
|
||||||
|
|||||||
Reference in New Issue
Block a user