Skip to content

Other HeaderMap implementations #854

Description

@adityashah1212

There is a usecase for preserving header order where I work. The current Request and Response types internally use HeaderMap, which doesn't guarantee preserving header order and may iterate with random ordering.

Proposal

Create a trait called Headers that implements methods required to interface with HeaderMap. This would also include making it a super trait over IntoIterator, FromIteratorandExtend`.

pub trait Headers: IntoIterator<Item = (HeaderName, HeaderValue)> ... {
   fn get(&self, name: &HeaderName) -> Option<&Vec<HeaderValue>>;

   fn insert(&mut self, name: HeaderName, value: HeaderValue);

   fn append(&mut self, name: HeaderName, value: HeaderValue);

   ...
}

This needs to be thought out a bit better. This is a very high level design

Now HeaderMap can implement this trait and Request and Response can be generic over this trait with default type of HeaderMap to keep other users unaffected.

Now all a user that is trying to override headers has to do is implement Headers on top of their own HeaderMap implementation. I don't expect http crate to handle other forms of HeaderMap either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions