Skip to main content

rust_web_server/http/
mod.rs

1#[cfg(test)]
2mod tests;
3pub(crate) mod date;
4
5pub struct Version {
6    pub http_0_9: &'static str,
7    pub http_1_0: &'static str,
8    pub http_1_1: &'static str,
9    pub http_2_0: &'static str,
10    pub http_3_0: &'static str,
11}
12
13pub const VERSION: Version = Version {
14    http_0_9: "HTTP/0.9",
15    http_1_0: "HTTP/1.0",
16    http_1_1: "HTTP/1.1",
17    http_2_0: "HTTP/2.0",
18    http_3_0: "HTTP/3.0",
19};
20
21pub struct HTTP;
22
23impl HTTP {
24    /// `true` if `version` (any case) is one of [`HTTP::version_list`],
25    /// without building that list.
26    pub fn is_supported_version(version: &str) -> bool {
27        [VERSION.http_0_9, VERSION.http_1_0, VERSION.http_1_1, VERSION.http_2_0, VERSION.http_3_0]
28            .iter()
29            .any(|v| v.eq_ignore_ascii_case(version))
30    }
31
32    pub fn version_list() -> Vec<String> {
33        let version_0_9 = VERSION.http_0_9.to_string();
34        let version_1_0 = VERSION.http_1_0.to_string();
35        let version_1_1 = VERSION.http_1_1.to_string();
36        let version_2_0 = VERSION.http_2_0.to_string();
37        let version_3_0 = VERSION.http_3_0.to_string();
38
39        let list : Vec<String> = vec![
40            version_0_9,
41            version_1_0,
42            version_1_1,
43            version_2_0,
44            version_3_0,
45        ];
46        list
47    }
48}