pub struct HttpClient {
pub default_headers: BTreeMap<String, String>,
pub timeout_ms: u64,
pub max_redirects: u8,
}Expand description
HTTP client with configurable defaults.
The client does not perform actual I/O. Instead, prepare_request() returns
serialized bytes to send over TCP, and parse_response() accepts received
bytes and returns an HttpResponse when complete.
Fields§
§default_headers: BTreeMap<String, String>Default headers applied to every request.
timeout_ms: u64Request timeout in milliseconds.
max_redirects: u8Maximum number of redirects to follow.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn set_default_header(&mut self, name: &str, value: &str)
pub fn set_default_header(&mut self, name: &str, value: &str)
Set a default header that will be applied to every request.
Sourcepub fn prepare_request(&self, request: &mut HttpRequest) -> Vec<u8>
pub fn prepare_request(&self, request: &mut HttpRequest) -> Vec<u8>
Prepare a request: apply default headers and serialize to bytes.
Sourcepub fn create_parser(&self) -> ResponseParser
pub fn create_parser(&self) -> ResponseParser
Create a new response parser for receiving response data.
Sourcepub fn get(&self, url: &str) -> Result<Vec<u8>, HttpError>
pub fn get(&self, url: &str) -> Result<Vec<u8>, HttpError>
Convenience: build and serialize a GET request.
Sourcepub fn post(
&self,
url: &str,
body: &[u8],
content_type: &str,
) -> Result<Vec<u8>, HttpError>
pub fn post( &self, url: &str, body: &[u8], content_type: &str, ) -> Result<Vec<u8>, HttpError>
Convenience: build and serialize a POST request with a body.
Sourcepub fn follow_redirect(
&self,
response: &HttpResponse,
original_url: &str,
remaining_redirects: &mut u8,
) -> Result<Option<HttpRequest>, HttpError>
pub fn follow_redirect( &self, response: &HttpResponse, original_url: &str, remaining_redirects: &mut u8, ) -> Result<Option<HttpRequest>, HttpError>
Process a redirect response: returns a new request to the redirect
location, or None if not a redirect. Decrements remaining_redirects.