22
src/agent.rs
22
src/agent.rs
@@ -54,6 +54,7 @@ pub(crate) struct AgentConfig {
|
|||||||
pub timeout_read: Option<Duration>,
|
pub timeout_read: Option<Duration>,
|
||||||
pub timeout_write: Option<Duration>,
|
pub timeout_write: Option<Duration>,
|
||||||
pub timeout: Option<Duration>,
|
pub timeout: Option<Duration>,
|
||||||
|
pub no_delay: bool,
|
||||||
pub redirects: u32,
|
pub redirects: u32,
|
||||||
pub redirect_auth_headers: RedirectAuthHeaders,
|
pub redirect_auth_headers: RedirectAuthHeaders,
|
||||||
pub user_agent: String,
|
pub user_agent: String,
|
||||||
@@ -238,6 +239,7 @@ impl AgentBuilder {
|
|||||||
timeout_read: None,
|
timeout_read: None,
|
||||||
timeout_write: None,
|
timeout_write: None,
|
||||||
timeout: None,
|
timeout: None,
|
||||||
|
no_delay: true,
|
||||||
redirects: 5,
|
redirects: 5,
|
||||||
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")),
|
||||||
@@ -433,6 +435,26 @@ impl AgentBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether no_delay will be set on the tcp socket.
|
||||||
|
/// Setting this to true disables Nagle's algorithm.
|
||||||
|
///
|
||||||
|
/// Defaults to true.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # fn main() -> Result<(), ureq::Error> {
|
||||||
|
/// # ureq::is_test(true);
|
||||||
|
/// let agent = ureq::builder()
|
||||||
|
/// .no_delay(false)
|
||||||
|
/// .build();
|
||||||
|
/// let result = agent.get("http://httpbin.org/get").call();
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
pub fn no_delay(mut self, no_delay: bool) -> Self {
|
||||||
|
self.config.no_delay = no_delay;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// How many redirects to follow.
|
/// How many redirects to follow.
|
||||||
///
|
///
|
||||||
/// Defaults to `5`. Set to `0` to avoid redirects and instead
|
/// Defaults to `5`. Set to `0` to avoid redirects and instead
|
||||||
|
|||||||
@@ -407,6 +407,8 @@ pub(crate) fn connect_host(unit: &Unit, hostname: &str, port: u16) -> Result<Tcp
|
|||||||
panic!("shouldn't happen: failed to connect to all IPs, but no error");
|
panic!("shouldn't happen: failed to connect to all IPs, but no error");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
stream.set_nodelay(unit.agent.config.no_delay)?;
|
||||||
|
|
||||||
if let Some(deadline) = unit.deadline {
|
if let Some(deadline) = unit.deadline {
|
||||||
stream.set_read_timeout(Some(time_until_deadline(deadline)?))?;
|
stream.set_read_timeout(Some(time_until_deadline(deadline)?))?;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user