pub struct Client { /* private fields */ }
client
only.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 features. To enable it you need to enable one of the following features:
native-tls
to use the current system native implementation.rustls-ring-webpki
to use Rustls with the Ring cryptographic library and the Common CA Database.rustls-ring-native
to use Rustls with the Ring cryptographic library and the host certificates.rustls-aws-lc-webpki
to use Rustls with the AWS Libcrypto for Rust and the Common CA Database.rustls-aws-lc-native
to use Rustls with the AWS Libcrypto for Rust and the host certificates.
If the flate2
feature is enabled, the client will automatically decode gzip
and deflate
content-encodings.
The client does not follow redirections by default. Use Client::with_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 with_global_timeout(self, timeout: Duration) -> Self
pub fn with_global_timeout(self, timeout: Duration) -> Self
Sets the global timeout value (applies to both read, write and connection).
sourcepub fn with_user_agent(
self,
user_agent: impl Into<String>
) -> Result<Self, InvalidHeader>
pub fn with_user_agent( self, user_agent: impl Into<String> ) -> Result<Self, InvalidHeader>
Sets the default value for the User-Agent
header.
sourcepub fn with_redirection_limit(self, limit: usize) -> Self
pub fn with_redirection_limit(self, limit: usize) -> Self
Sets the number of time a redirection should be followed. By default the redirections are not followed (limit = 0).