pub struct Request {
pub method: HttpMethod,
pub url: Url,
pub headers: Headers,
pub body: Option<Vec<u8>>,
}Expand description
HTTP request.
Fields§
§method: HttpMethodHTTP method (GET, POST, etc.).
url: UrlTarget URL.
headers: HeadersRequest headers.
body: Option<Vec<u8>>Optional request body.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(method: HttpMethod, url: Url) -> Self
pub fn new(method: HttpMethod, url: Url) -> Self
Create a new request with the given method and URL.
Sourcepub fn with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Set a header.
Sourcepub fn with_content_type(self, content_type: impl Into<String>) -> Self
pub fn with_content_type(self, content_type: impl Into<String>) -> Self
Set Content-Type header.
Sourcepub fn method_str(&self) -> &'static str
pub fn method_str(&self) -> &'static str
Get the request method as string.
Sourcepub fn to_wire_format(&self) -> Vec<u8>
pub fn to_wire_format(&self) -> Vec<u8>
Serialize the request to HTTP/1.1 wire format.
Format:
METHOD /path HTTP/1.1\r\n
Header: Value\r\n
...
\r\n
[body]Trait Implementations§
Auto Trait Implementations§
impl Freeze for Request
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnwindSafe for Request
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more