pub struct Request<'body> { /* private fields */ }
Expand description
Represent an unsent query.
Calling send
actually makes the request.
Implementations
sourceimpl<'body> Request<'body>
impl<'body> Request<'body>
sourcepub fn new(method: Method, url: String) -> Request<'body>
pub fn new(method: Method, url: String) -> Request<'body>
Create a request for a specific HTTP method and Url
sourcepub fn get(url: String) -> Self
pub fn get(url: String) -> Self
create a GET request
You may then use the builder-pattern to configure the request
and then call send()
to begin it
sourcepub fn post(url: String) -> Self
pub fn post(url: String) -> Self
create a POST request
You should specify a payload to send with body()
or set_body()
, which will be read
before the request turns into a Response.
sourcepub fn put(url: String) -> Self
pub fn put(url: String) -> Self
create a PUT request
You should specify a payload to send with body()
or set_body()
, which will be read
before the request turns into a Response.
sourcepub fn set_content_length(&mut self, l: u64)
pub fn set_content_length(&mut self, l: u64)
set the HTTP Content-Length header
This is the number of bytes expected to be read by body()
.
If specified, the value is sent as the Content-Length
header.
It does not matter to curl if you specify the wrong value, but the server may object.
sourcepub fn content_length(self, l: u64) -> Self
pub fn content_length(self, l: u64) -> Self
set the HTTP Content-Length header
This is the number of bytes expected to be read by body()
.
If specified, the value is sent as the Content-Length
header. Either way, curl will use
Transfer-Encoding: chunked
.
It does not matter to curl if you specify the wrong value, but the server may object.
sourcepub fn set_header<K, V>(&mut self, k: K, v: V) where
K: AsRef<[u8]>,
V: AsRef<[u8]>,
pub fn set_header<K, V>(&mut self, k: K, v: V) where
K: AsRef<[u8]>,
V: AsRef<[u8]>,
Add one HTTP header to the request.
Any values may be sent, even those that may be invalid
according to the HTTP specification. You should
prefer to use the Header
constants
in the idcurl::Header
module.
pub fn header<K, V>(self, k: K, v: V) -> Self where
K: AsRef<[u8]>,
V: AsRef<[u8]>,
sourcepub fn set_body<R: 'body>(&mut self, r: R) where
R: Read + 'body,
pub fn set_body<R: 'body>(&mut self, r: R) where
R: Read + 'body,
Sets the reader which the payload to send is read from
The entire body is read before send()
completes.
The body is not read for the GET and DELETE methods.
The specified body, if a reference, must outlive this Request
.
sourcepub fn body<'b, R: 'b>(self, r: R) -> Request<'b> where
R: Read + 'b,
pub fn body<'b, R: 'b>(self, r: R) -> Request<'b> where
R: Read + 'b,
Sets the reader which the payload to send is read from
The entire body is read before send()
completes.
The body is not read for the GET and DELETE methods.
The returned Request
has the lifetime of your Read, because
the body you intend to send needs to outlive the Request. You
can either give a reference with a reader (example:
Cursor::new(&my_vector_object)
) or you can give ownership
(Cursor::new(owned_vector)
).
sourcepub fn send(self) -> Result<Response>
pub fn send(self) -> Result<Response>
Make the HTTP request.
The configured request is sent along with its headers,
then if specified, the body
is sent
if the Method is appropriate.
The function succeeds and you get a Response if the server could be contacted and an HTTP session was initiated.
You should then call Response::status().is_success()
to check for an HTTP status code in the 200 range.
sourcepub fn set_redirect_limit(&mut self, n: Option<usize>) -> &mut Self
pub fn set_redirect_limit(&mut self, n: Option<usize>) -> &mut Self
sets the number of redirects that will be followed
The default is 10. An error will be returned if the number is exceeded.
Specify None
to disable handling redirects. A redirect
is not an error, instead you will get a Response
for the redirect response.
sourcepub fn redirect_limit(self, n: Option<usize>) -> Self
pub fn redirect_limit(self, n: Option<usize>) -> Self
sets the number of redirects that will be followed
The default is 10. An error will be returned if the number is exceeded.
Specify None
to disable handling redirects. A redirect
is not an error, instead you will get a Response
for the redirect response.
Auto Trait Implementations
impl<'body> !RefUnwindSafe for Request<'body>
impl<'body> !Send for Request<'body>
impl<'body> !Sync for Request<'body>
impl<'body> Unpin for Request<'body>
impl<'body> !UnwindSafe for Request<'body>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more