[][src]Struct http_req::response::Response

pub struct Response { /* fields omitted */ }

Represents an HTTP response.

It contains Headers and Status parsed from response.

Methods

impl Response[src]

pub fn from_head(head: &[u8]) -> Result<Response, Error>[src]

Creates new Response with head - status and headers - parsed from a slice of bytes

Examples

use http_req::response::Response;

const HEAD: &[u8; 102] = b"HTTP/1.1 200 OK\r\n\
                         Date: Sat, 11 Jan 2003 02:44:04 GMT\r\n\
                         Content-Type: text/html\r\n\
                         Content-Length: 100\r\n\r\n";

let response = Response::from_head(HEAD).unwrap();

pub fn try_from<T: Write>(res: &[u8], writer: &mut T) -> Result<Response, Error>[src]

Parses Response from slice of bytes. Writes it's body to writer.

Examples

use http_req::response::Response;

const RESPONSE: &[u8; 129] = b"HTTP/1.1 200 OK\r\n\
                             Date: Sat, 11 Jan 2003 02:44:04 GMT\r\n\
                             Content-Type: text/html\r\n\
                             Content-Length: 100\r\n\r\n\
                             <html>hello\r\n\r\nhello</html>";
let mut body = Vec::new();

let response = Response::try_from(RESPONSE, &mut body).unwrap();

pub fn status_code(&self) -> StatusCode[src]

Returns status code of this Response.

Examples

use http_req::response::{Response, StatusCode};

const RESPONSE: &[u8; 129] = b"HTTP/1.1 200 OK\r\n\
                             Date: Sat, 11 Jan 2003 02:44:04 GMT\r\n\
                             Content-Type: text/html\r\n\
                             Content-Length: 100\r\n\r\n\
                             <html>hello\r\n\r\nhello</html>";
let mut body = Vec::new();

let response = Response::try_from(RESPONSE, &mut body).unwrap();
assert_eq!(response.status_code(), StatusCode::new(200));

pub fn version(&self) -> &str[src]

Returns HTTP version of this Response.

Examples

use http_req::response::Response;

const RESPONSE: &[u8; 129] = b"HTTP/1.1 200 OK\r\n\
                             Date: Sat, 11 Jan 2003 02:44:04 GMT\r\n\
                             Content-Type: text/html\r\n\
                             Content-Length: 100\r\n\r\n\
                             <html>hello\r\n\r\nhello</html>";
let mut body = Vec::new();

let response = Response::try_from(RESPONSE, &mut body).unwrap();
assert_eq!(response.version(), "HTTP/1.1");

pub fn reason(&self) -> &str[src]

Returns reason of this Response.

Examples

use http_req::response::Response;

const RESPONSE: &[u8; 129] = b"HTTP/1.1 200 OK\r\n\
                             Date: Sat, 11 Jan 2003 02:44:04 GMT\r\n\
                             Content-Type: text/html\r\n\
                             Content-Length: 100\r\n\r\n\
                             <html>hello\r\n\r\nhello</html>";
let mut body = Vec::new();

let response = Response::try_from(RESPONSE, &mut body).unwrap();
assert_eq!(response.reason(), "OK");

pub fn headers(&self) -> &Headers[src]

Returns headers of this Response.

Examples

use http_req::response::Response;

const RESPONSE: &[u8; 129] = b"HTTP/1.1 200 OK\r\n\
                             Date: Sat, 11 Jan 2003 02:44:04 GMT\r\n\
                             Content-Type: text/html\r\n\
                             Content-Length: 100\r\n\r\n\
                             <html>hello\r\n\r\nhello</html>";
let mut body = Vec::new();

let response = Response::try_from(RESPONSE, &mut body).unwrap();
let headers = response.headers();

pub fn content_len(&self) -> Result<usize, ParseErr>[src]

Returns length of the content of this Response as a Result, according to information included in headers. If there is no such an information, returns Ok(0).

Examples

use http_req::response::Response;

const RESPONSE: &[u8; 129] = b"HTTP/1.1 200 OK\r\n\
                             Date: Sat, 11 Jan 2003 02:44:04 GMT\r\n\
                             Content-Type: text/html\r\n\
                             Content-Length: 100\r\n\r\n\
                             <html>hello\r\n\r\nhello</html>";
let mut body = Vec::new();

let response = Response::try_from(RESPONSE, &mut body).unwrap();
assert_eq!(response.content_len().unwrap(), 100);

Trait Implementations

impl PartialEq<Response> for Response[src]

impl Clone for Response[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Response[src]

Auto Trait Implementations

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

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

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

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