pub trait RequestExt<S>where
S: AsSendBody,{
// Required method
fn with_agent<'a>(self, agent: impl Into<AgentRef<'a>>) -> WithAgent<'a, S>;
// Provided method
fn with_default_agent(self) -> WithAgent<'static, S>
where Self: Sized { ... }
}Expand description
Extension trait for http::Request<impl AsSendBody>.
Adds additional convenience methods to the Request that are not available
in the plain http API.
Required Methods§
Sourcefn with_agent<'a>(self, agent: impl Into<AgentRef<'a>>) -> WithAgent<'a, S>
fn with_agent<'a>(self, agent: impl Into<AgentRef<'a>>) -> WithAgent<'a, S>
Allows configuring this request behaviour, using a specific Agent.
This method allows configuring the request by using a user-provided Agent and performing
additional configurations on top.
This method returns a WithAgent struct that it is possible to call configure() and run()
on to configure the request behaviour, or run the request.
§Example
use ureq::{http, Agent, RequestExt, Error};
use std::time::Duration;
let agent = Agent::config_builder()
.timeout_global(Some(Duration::from_secs(30)))
.build()
.new_agent();
let request: Result<http::Response<_>, Error> = http::Request::builder()
.method(http::Method::GET)
.uri("http://foo.bar")
.body(())
.unwrap()
.with_agent(&agent)
.run();§Example with further customizations
In this example we use a specific agent, but apply a request-specific configuration on top.
use ureq::{http, Agent, RequestExt, Error};
use std::time::Duration;
let mut agent = Agent::config_builder()
.timeout_global(Some(Duration::from_secs(30)))
.build()
.new_agent();
let request: Result<http::Response<_>, Error> = http::Request::builder()
.method(http::Method::GET)
.uri("http://foo.bar")
.body(())
.unwrap()
.with_agent(&agent)
.configure()
.http_status_as_error(false)
.run();Provided Methods§
Sourcefn with_default_agent(self) -> WithAgent<'static, S>where
Self: Sized,
fn with_default_agent(self) -> WithAgent<'static, S>where
Self: Sized,
Allows configuring the request behaviour, starting with the default Agent.
This method allows configuring the request by using the default Agent, and performing
additional configurations on top.
This method returns a WithAgent struct that it is possible to call configure() and run()
on to configure the request behaviour, or run the request.
§Example
use ureq::{http, RequestExt, Error};
let request: Result<http::Response<_>, Error> = http::Request::builder()
.method(http::Method::GET)
.uri("http://foo.bar")
.body(())
.unwrap()
.with_default_agent()
.configure()
.http_status_as_error(false)
.run();Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.