tinyhttp_internal/
lib.rs

1//#![warn(missing_docs)]
2#![warn(clippy::all)]
3
4pub mod codegen;
5pub mod config;
6pub mod request;
7pub mod response;
8
9#[cfg(not(feature = "async"))]
10pub mod http;
11
12#[cfg(feature = "async")]
13pub mod async_http;
14
15#[cfg(test)]
16mod tests {
17    use std::collections::HashMap;
18
19    #[test]
20    fn build_request() {
21        use crate::request::Request;
22        let mut headers = HashMap::new();
23        headers.insert("content-type".to_string(), "text/plain".to_string());
24
25        let request = Request::new(
26            b"Hello, World!".to_vec(),
27            headers,
28            vec![
29                "GET".to_string(),
30                "/test".to_string(),
31                "HTTP/1.1".to_string(),
32            ],
33            None,
34        );
35        assert_eq!(
36            *request.get_parsed_body().unwrap(),
37            "Hello, World!".to_string()
38        )
39    }
40    #[test]
41    fn build_response() {
42        use crate::response::Response;
43
44        let response = Response::new()
45            .body(b"1 2 3 test test...".to_vec())
46            .status_line("HTTP/1.1 200 OK");
47
48        assert_eq!(
49            String::from_utf8(response.body.unwrap()).unwrap(),
50            String::from("1 2 3 test test...")
51        );
52    }
53}