]> git.proxmox.com Git - proxmox.git/blame - proxmox-rest-server/src/compression.rs
rest-server: cleanup unreadable code
[proxmox.git] / proxmox-rest-server / src / compression.rs
CommitLineData
d28249c2
DC
1use anyhow::{bail, Error};
2use hyper::header;
3
4/// Possible Compression Methods, order determines preference (later is preferred)
5#[derive(Eq, Ord, PartialEq, PartialOrd, Debug)]
6pub enum CompressionMethod {
7 Deflate,
2bda552b
TL
8 // Gzip,
9 // Brotli,
d28249c2
DC
10}
11
12impl CompressionMethod {
13 pub fn content_encoding(&self) -> header::HeaderValue {
14 header::HeaderValue::from_static(self.extension())
15 }
16
17 pub fn extension(&self) -> &'static str {
18 match *self {
2bda552b
TL
19 // CompressionMethod::Brotli => "br",
20 // CompressionMethod::Gzip => "gzip",
d28249c2
DC
21 CompressionMethod::Deflate => "deflate",
22 }
23 }
24}
25
26impl std::str::FromStr for CompressionMethod {
27 type Err = Error;
28
29 fn from_str(s: &str) -> Result<Self, Self::Err> {
30 match s {
2bda552b
TL
31 // "br" => Ok(CompressionMethod::Brotli),
32 // "gzip" => Ok(CompressionMethod::Gzip),
d28249c2
DC
33 "deflate" => Ok(CompressionMethod::Deflate),
34 // http accept-encoding allows to give weights with ';q='
35 other if other.starts_with("deflate;q=") => Ok(CompressionMethod::Deflate),
36 _ => bail!("unknown compression format"),
37 }
38 }
39}