little_hyper/
request.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::headers::Headers;
use crate::path::PathData;
use crate::path::path_regex::Params;
use crate::query::QueryData;

#[derive(Debug)]
pub struct Request {
    /// Method
    ///
    pub method: String,
    /// Path
    ///
    pub path: String,
    /// Pathname
    ///
    pub pathname: String,
    /// Params
    ///
    /// TODO: delete this one, after PathExtractor ready.
    pub params: Params,
    /// Querystring
    ///
    pub querystring: String,
    /// Query
    ///
    pub query: QueryData,
    /// Http Version
    ///
    pub version: String,
    /// Headers
    ///
    pub headers: Headers,
    /// Body
    ///
    pub body: String,
}

impl From<Vec<String>> for Request {
    fn from(value: Vec<String>) -> Self {
        let heading_info = value[0].split(' ').collect::<Vec<&str>>();

        let PathData {
            path,
            pathname,
            querystring,
            query,
        } = PathData::new(heading_info[1]);

        let body = "".to_string();

        Request {
            method: heading_info[0].to_string(),
            version: heading_info[2].to_string(),
            path,
            pathname,
            params: Params::new(),
            query,
            querystring,
            headers: Headers::from(&value[1..]),
            body,
        }
    }
}