hyperium / headers

Typed HTTP Headers from hyper
https://hyper.rs
MIT License
162 stars 84 forks source link

Add methods for `must-revalidate` flag to `CacheControl` #186

Closed allenap closed 2 months ago

allenap commented 2 months ago

The must-revalidate flag is supported. This adds the methods to test for its existence in and/or to add it to CacheControl.

Fixes #189.

allenap commented 2 months ago

Fwiw, my current workaround is borrowed from test_decode:

use headers::{self, HeaderMapExt};

fn decode<T: headers::Header>(values: &[&str]) -> Option<T> {
    let mut map = http::HeaderMap::new();
    for val in values {
        map.append(T::name(), val.parse().unwrap());
    }
    map.typed_get()
}

let cache_control = decode::<headers::CacheControl>(&["must-revalidate"]).unwrap();
let cache_control = Header(cache_control.with_public().with_max_age(Duration::ZERO));