pub struct Client { /* private fields */ }
Expand description
An HTTP client.
It aims at following the basic concepts of the Web Fetch standard without the bits specific to web browsers (context, CORS…).
HTTPS is supported behind the disabled by default native-tls
feature (to use the current system native implementation) or rustls
feature (to use Rustls).
The client does not follow redirections by default. Use Client::set_redirection_limit
to set a limit to the number of consecutive redirections the server should follow.
Missing: HSTS support, authentication and keep alive.
use oxhttp::Client;
use oxhttp::model::{Request, Method, Status, HeaderName};
use std::io::Read;
let client = Client::new();
let response = client.request(Request::builder(Method::GET, "http://example.com".parse()?).build())?;
assert_eq!(response.status(), Status::OK);
assert_eq!(response.header(&HeaderName::CONTENT_TYPE).unwrap().as_ref(), b"text/html; charset=UTF-8");
let body = response.into_body().to_string()?;
Implementations§
source§impl Client
impl Client
pub fn new() -> Self
sourcepub fn set_global_timeout(&mut self, timeout: Duration)
pub fn set_global_timeout(&mut self, timeout: Duration)
Sets the global timeout value (applies to both read, write and connection).
sourcepub fn set_user_agent(
&mut self,
user_agent: impl Into<String>
) -> Result<(), InvalidHeader>
pub fn set_user_agent( &mut self, user_agent: impl Into<String> ) -> Result<(), InvalidHeader>
Sets the default value for the User-Agent
header.
sourcepub fn set_redirection_limit(&mut self, limit: usize)
pub fn set_redirection_limit(&mut self, limit: usize)
Sets the number of time a redirection should be followed. By default the redirections are not followed (limit = 0).