pub struct Request { /* private fields */ }
Expand description
Request
is the main way of performing requests.
Use one of its contructors to create a request and then use the send
method
to send the Request
and get the status, headers and response.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(base_url: &str, method: Method) -> Request
pub fn new(base_url: &str, method: Method) -> Request
Create a new Request
with the base URL and the given method.
Sourcepub fn param<V>(&mut self, key: &str, value: V)where
V: Display,
pub fn param<V>(&mut self, key: &str, value: V)where
V: Display,
Associate a query string parameter to the given value.
The same key can be used multiple times.
Sourcepub fn header<H, V>(&mut self, header: H, value: V) -> HttpResultwhere
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
pub fn header<H, V>(&mut self, header: H, value: V) -> HttpResultwhere
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
Modify a header for this Request
.
If the header is already present, the value will be replaced. If you wish to append a new header,
use header_append
.
Sourcepub fn header_append<H, V>(&mut self, header: H, value: V) -> HttpResultwhere
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
pub fn header_append<H, V>(&mut self, header: H, value: V) -> HttpResultwhere
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
Append a new header to this Request
.
The new header is always appended to the Request
, even if the header already exists.
Sourcepub fn body(&mut self, body: impl AsRef<[u8]>)
pub fn body(&mut self, body: impl AsRef<[u8]>)
Set the body of this request.
The can be a &[u8]
or a str
, anything that’s a sequence of bytes.
Sourcepub fn follow_redirects(&mut self, follow_redirects: bool)
pub fn follow_redirects(&mut self, follow_redirects: bool)
Sets if this Request
should follow redirects, 3xx codes.
This value defaults to true.
Sourcepub fn default_charset(&mut self, default_charset: Option<Charset>)
pub fn default_charset(&mut self, default_charset: Option<Charset>)
Set the default charset to use while parsing the response of this Request
.
If the response does not say which charset it uses, this charset will be used to decode the request.
This value defaults to None
, in which case ISO-8859-1 is used.
Sourcepub fn allow_compression(&mut self, allow_compression: bool)
pub fn allow_compression(&mut self, allow_compression: bool)
Sets if this Request
will announce that it accepts compression.
This value defaults to true. Note that this only lets the browser know that this Request
supports
compression, the server might choose not to compress the content.
Sourcepub fn send(self) -> HttpResult<(StatusCode, HeaderMap, ResponseReader)>
pub fn send(self) -> HttpResult<(StatusCode, HeaderMap, ResponseReader)>
Send this Request
to the server.
This method consumes the object so that it cannot be used after sending the request.