[−][src]Struct http_req::response::Response
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) -> Option<usize>
[src]
Returns length of the content of this Response
as a Option
, according to information
included in headers. If there is no such an information, returns None
.
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 Clone for Response
[src]
impl Debug for Response
[src]
impl PartialEq<Response> for Response
[src]
impl StructuralPartialEq for Response
[src]
Auto Trait Implementations
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> 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, U> TryFrom<U> 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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,