pub struct HttpRequest {
pub method: HttpMethod,
pub url: ParsedUrl,
pub headers: BTreeMap<String, String>,
pub body: Option<Vec<u8>>,
}Expand description
An HTTP request ready to be serialized and sent.
Fields§
§method: HttpMethodHTTP method
url: ParsedUrlParsed URL
headers: BTreeMap<String, String>Headers (lowercase key -> value)
body: Option<Vec<u8>>Optional request body
Implementations§
Source§impl HttpRequest
impl HttpRequest
Sourcepub fn new(method: HttpMethod, url: &str) -> Result<Self, HttpError>
pub fn new(method: HttpMethod, url: &str) -> Result<Self, HttpError>
Create a new request with default headers.
Sourcepub fn set_header(&mut self, name: &str, value: &str)
pub fn set_header(&mut self, name: &str, value: &str)
Set a header (name is stored lowercase).
Sourcepub fn set_body(&mut self, body: Vec<u8>)
pub fn set_body(&mut self, body: Vec<u8>)
Set the request body and automatically set Content-Length.
Sourcepub fn set_body_str(&mut self, body: &str)
pub fn set_body_str(&mut self, body: &str)
Set the request body from a string.
Sourcepub fn set_content_type(&mut self, mime: &str)
pub fn set_content_type(&mut self, mime: &str)
Set Content-Type header.
Sourcepub fn set_basic_auth(&mut self, user: &str, password: &str)
pub fn set_basic_auth(&mut self, user: &str, password: &str)
Set Authorization header with Basic auth (Base64-encoded user:password).
Set Cookie header from a list of (name, value) pairs.
Trait Implementations§
Source§impl Clone for HttpRequest
impl Clone for HttpRequest
Source§fn clone(&self) -> HttpRequest
fn clone(&self) -> HttpRequest
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for HttpRequest
impl RefUnwindSafe for HttpRequest
impl Send for HttpRequest
impl Sync for HttpRequest
impl Unpin for HttpRequest
impl UnwindSafe for HttpRequest
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)