[−][src]Struct http_req::request::Request
Relatively higher-level struct for making HTTP requests.
It creates stream (TcpStream
or TlsStream
) appropriate for the type of uri (http
/https
)
By default it closes connection after completion of the response.
About timeouts:
- Default timeout for starting connection is 1 minute.
- On Linux,
man 7 socket
says that read/write timeouts default to zero, which means the operations will never time out. However, default value for this builder is 1 minute each.
Examples
use http_req::{request::Request, uri::Uri, response::StatusCode}; let mut writer = Vec::new(); let uri: Uri = "https://doc.rust-lang.org/".parse().unwrap(); let mut response = Request::new(&uri).send(&mut writer).unwrap();; assert_eq!(response.status_code(), StatusCode::new(200));
Methods
impl<'a> Request<'a>
[src]
pub fn new(uri: &'a Uri) -> Request<'a>
[src]
Creates new Request
with default parameters
pub fn headers<T>(&mut self, headers: T) -> &mut Self where
Headers: From<T>,
[src]
Headers: From<T>,
Replaces all it's headers with headers passed to the function
pub fn header<T: ?Sized, U: ?Sized>(&mut self, key: &T, val: &U) -> &mut Self where
T: ToString,
U: ToString,
[src]
T: ToString,
U: ToString,
Adds header to existing/default headers
pub fn method<T>(&mut self, method: T) -> &mut Self where
Method: From<T>,
[src]
Method: From<T>,
Changes request's method
pub fn set_method<T>(&mut self, method: T) where
Method: From<T>,
[src]
Method: From<T>,
Please use method instead
pub fn body(&mut self, body: &'a [u8]) -> &mut Self
[src]
Sets body for request
pub fn connect_timeout<T>(&mut self, timeout: Option<T>) -> &mut Self where
Duration: From<T>,
[src]
Duration: From<T>,
Sets connect timeout while using internal TcpStream
instance
- If there is a timeout, it will be passed to
TcpStream::connect_timeout
. - If
None
is provided,TcpStream::connect
will be used, and it will not time out.
pub fn set_connect_timeout(&mut self, timeout: Option<Duration>) -> &mut Self
[src]
Please use the read_timeout instead
pub fn read_timeout<T>(&mut self, timeout: Option<T>) -> &mut Self where
Duration: From<T>,
[src]
Duration: From<T>,
Sets read timeout on internal TcpStream
instance
timeout
will be passed to
TcpStream::set_read_timeout
.
pub fn set_read_timeout(&mut self, timeout: Option<Duration>) -> &mut Self
[src]
Please use the read_timeout instead
pub fn write_timeout<T>(&mut self, timeout: Option<T>) -> &mut Self where
Duration: From<T>,
[src]
Duration: From<T>,
Sets write timeout on internal TcpStream
instance
timeout
will be passed to
TcpStream::set_write_timeout
.
pub fn set_write_timeout(&mut self, timeout: Option<Duration>) -> &mut Self
[src]
Please use the write_timeout instead
pub fn send<T: Write>(&self, writer: &mut T) -> Result<Response, Error>
[src]
Sends HTTP request.
Creates TcpStream
(and wraps it with TlsStream
if needed). Writes request message
to created stream. Returns response for this request. Writes response's body to writer
.
Trait Implementations
impl<'a> PartialEq<Request<'a>> for Request<'a>
[src]
impl<'a> Clone for Request<'a>
[src]
fn clone(&self) -> Request<'a>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'a> Debug for Request<'a>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,