make local_addr syscall unconditional
This commit is contained in:
committed by
Martin Algesten
parent
7e32dbaaaf
commit
11a8eb470c
26
src/agent.rs
26
src/agent.rs
@@ -78,7 +78,6 @@ pub(crate) struct AgentConfig {
|
||||
pub redirect_auth_headers: RedirectAuthHeaders,
|
||||
pub user_agent: String,
|
||||
pub tls_config: TlsConfig,
|
||||
pub get_local_addr: bool,
|
||||
}
|
||||
|
||||
/// Agents keep state between requests.
|
||||
@@ -263,7 +262,6 @@ impl AgentBuilder {
|
||||
redirect_auth_headers: RedirectAuthHeaders::Never,
|
||||
user_agent: format!("ureq/{}", env!("CARGO_PKG_VERSION")),
|
||||
tls_config: TlsConfig(crate::default_tls_config()),
|
||||
get_local_addr: false,
|
||||
},
|
||||
max_idle_connections: DEFAULT_MAX_IDLE_CONNECTIONS,
|
||||
max_idle_connections_per_host: DEFAULT_MAX_IDLE_CONNECTIONS_PER_HOST,
|
||||
@@ -622,30 +620,6 @@ impl AgentBuilder {
|
||||
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.
|
||||
///
|
||||
/// This is useful in two cases. First when there is a need to persist cookies
|
||||
|
||||
@@ -78,8 +78,7 @@ pub struct Response {
|
||||
pub(crate) reader: Box<dyn Read + Send + Sync + 'static>,
|
||||
/// The socket address of the server that sent the response.
|
||||
pub(crate) remote_addr: SocketAddr,
|
||||
/// Local address request was sent from. Only set if necessary since
|
||||
/// it is an extra system call.
|
||||
/// The socket address of the client that sent the request.
|
||||
pub(crate) local_addr: Option<SocketAddr>,
|
||||
/// The redirect history of this response, if any. The history starts with
|
||||
/// the first response received and ends with the response immediately
|
||||
@@ -236,8 +235,6 @@ impl Response {
|
||||
}
|
||||
|
||||
/// The local address the request was made from.
|
||||
///
|
||||
/// This is only available if [`AgentBuilder::get_local_addr()`][crate::AgentBuilder] is set to true.
|
||||
pub fn local_addr(&self) -> Option<SocketAddr> {
|
||||
self.local_addr
|
||||
}
|
||||
@@ -544,13 +541,7 @@ impl Response {
|
||||
pub(crate) fn do_from_stream(stream: Stream, unit: Unit) -> Result<Response, Error> {
|
||||
let remote_addr = stream.remote_addr;
|
||||
|
||||
// Only read local_addr if configured to do so, since it's another syscall.
|
||||
let mut local_addr = None;
|
||||
if unit.agent.config.get_local_addr {
|
||||
if let Some(socket) = stream.socket() {
|
||||
local_addr = Some(socket.local_addr()?);
|
||||
}
|
||||
}
|
||||
let local_addr = stream.socket().map(|s| s.local_addr().unwrap());
|
||||
|
||||
//
|
||||
// HTTP/1.1 200 OK\r\n
|
||||
|
||||
Reference in New Issue
Block a user