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
//#![warn(missing_docs)]
#![warn(clippy::all)]

pub mod codegen;
pub mod config;
pub mod request;
pub mod response;

#[cfg(not(feature = "async"))]
pub mod http;

#[cfg(feature = "async")]
pub mod async_http;

#[cfg(test)]
mod tests {
    use std::collections::HashMap;

    #[test]
    fn build_request() {
        use crate::request::Request;
        let mut headers = HashMap::new();
        headers.insert("content-type".to_string(), "text/plain".to_string());

        let request = Request::new(
            b"Hello, World!".to_vec(),
            headers,
            vec![
                "GET".to_string(),
                "/test".to_string(),
                "HTTP/1.1".to_string(),
            ],
            None,
        );
        assert_eq!(
            *request.get_parsed_body().unwrap(),
            "Hello, World!".to_string()
        )
    }
    #[test]
    fn build_response() {
        use crate::response::Response;

        let response = Response::new()
            .body(b"1 2 3 test test...".to_vec())
            .status_line("HTTP/1.1 200 OK");

        assert_eq!(
            String::from_utf8(response.body.unwrap()).unwrap(),
            String::from("1 2 3 test test...")
        );
    }
}