[][src]Struct http_req::request::Request

pub struct Request<'a> { /* fields omitted */ }

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]

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]

Adds header to existing/default headers

pub fn method<T>(&mut self, method: T) -> &mut Self where
    Method: From<T>, 
[src]

Changes request's method

pub fn set_method<T>(&mut self, method: T) where
    Method: From<T>, 
[src]

Deprecated:

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]

Sets connect timeout while using internal TcpStream instance

pub fn set_connect_timeout(&mut self, timeout: Option<Duration>) -> &mut Self[src]

Deprecated:

Please use the read_timeout instead

pub fn read_timeout<T>(&mut self, timeout: Option<T>) -> &mut Self where
    Duration: From<T>, 
[src]

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]

Deprecated:

Please use the read_timeout instead

pub fn write_timeout<T>(&mut self, timeout: Option<T>) -> &mut Self where
    Duration: From<T>, 
[src]

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]

Deprecated:

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_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

impl<'a> Send for Request<'a>

impl<'a> Sync for Request<'a>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.