Skip to main content

rws_base/http/
mod.rs

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