tinyhttp_internal/
lib.rs

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