Fishrock123 / tide-compress

Outgoing compression middleware for the Tide web framework.
https://crates.io/crates/tide-compress
Other
24 stars 7 forks source link

failed to detect accept-encoding #2

Closed SchrodingerZhu closed 4 years ago

SchrodingerZhu commented 4 years ago
fn accepts_encoding<State: Send + Sync + 'static>(req: &Request<State>) -> Option<Encoding> {
    let header = req.header(headers::ACCEPT_ENCODING)?;
    println!("{:?}", header.iter().collect::<Vec<_>>());
    #[cfg(feature = "brotli")]
    {
        if header.iter().any(|v| v.as_str() == "br") {
            return Some(Encoding::BROTLI);
        }
    }

    #[cfg(feature = "gzip")]
    {
        if header.iter().any(|v| v.as_str() == "gzip") {
            return Some(Encoding::GZIP);
        }
    }

    #[cfg(feature = "deflate")]
    {
        if header.iter().any(|v| v.as_str() == "deflate") {
            return Some(Encoding::DEFLATE);
        }
    }

    None
}

and we get:

["gzip, deflate"]

which means the value is not spitted. will open a PR for this later.

Fishrock123 commented 4 years ago

Yeah... that fix should do for now. Eventually this needs full Content-Encoding handling, which is something I am working on for http-types.