[][src]Struct http_str::Request

pub struct Request<'a> {
    pub entire_req: &'a str,
    pub method: &'a str,
    pub uri: &'a str,
    pub query: &'a str,
    pub version: &'a str,
    pub body: &'a str,
    pub headers_map: BTreeMap<&'a str, Vec<&'a str>>,
    // some fields omitted
}

Fields

entire_req: &'a strmethod: &'a struri: &'a strquery: &'a strversion: &'a strbody: &'a strheaders_map: BTreeMap<&'a str, Vec<&'a str>>

Methods

impl<'a> Request<'a>[src]

pub fn new(bytes: &'a [u8]) -> Pin<Box<Self>>[src]

Creates a new Request from a slice of bytes utf8 encoded forming a http request.

It is up to the caller that these bytes are valid utf8.

Panics

This function will panic if the bytes contain no space character(32).

Examples

use std::str::from_utf8_unchecked;
use http_str::Request;

let req = b"GET /index.html?myquery HTTP/1.1\r\nHost: www.example.com\r\nHello world!";
let request = Request::new(req);

assert_eq!(request.entire_req, unsafe { from_utf8_unchecked(req) });
assert_eq!(request.method, "GET"); // all the other fields refer to `entire_req`
assert_eq!(request.uri, "/index.html");
assert_eq!(request.query, "myquery");
assert_eq!(request.version, "HTTP/1.1");
assert_eq!(request.headers_map["Host"], vec!["www.example.com"]);
assert_eq!(request.body, "Hello world!");

pub fn with_method_len(bytes: &'a [u8], method_len: usize) -> Pin<Box<Self>>[src]

Creates a new Request from a slice of bytes utf8 encoded forming a http request and the length of the http method.

This will not produce the correct result if method_len is incorrect but takes less time than the normal constructor, use it when you do know the method of the request.

Trait Implementations

impl<'a> Display for Request<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Request<'a>

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

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

impl<'a> !Unpin for Request<'a>

impl<'a> UnwindSafe for Request<'a>

Blanket Implementations

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

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

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

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

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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

type Error = !

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.