hyperium / hyperium/http

A feature request: implement `retain` on HeaderMap

Open
#632 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.4k
Forks
378
Avg merge
1d 21h
Merged PRs (30d)
5

Description

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));

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the HeaderMap implementation and its existing mutation-method tests, then read how closures are used by nearby APIs. Add the requested retain behavior for filtering header entries and cover both retained and removed headers in tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.