hyperium/http

A feature request: implement `retain` on HeaderMap

bassmanitram opened this issue · 0 comments

It would be really handy to have the retain method available (as per std::collections) in order to allow headers to be removed based upon a closure. This would, for example, avoid the double-scan and "clone key" issues when one has a list of headers that must be retained or removed:

let delete_list: Vec<HeaderName> = headers
            .keys()
            .filter(|k| !allowed_headers.contains(*k))
            .map(|k| k.clone())
            .collect::<Vec<HeaderName>>();
for header in delete_list {
    headers.remove(header);
}

would be replaced with

headers.retain(|(k,v)| allowed_headers.contains(*k));