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.
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
Headersthat implements methods required to interface withHeaderMap. This would also include making it a super trait overIntoIterator,FromIteratorandExtend`.This needs to be thought out a bit better. This is a very high level design
Now HeaderMap can implement this trait and
RequestandResponsecan be generic over this trait with default type ofHeaderMapto keep other users unaffected.Now all a user that is trying to override headers has to do is implement
Headerson top of their own HeaderMap implementation. I don't expecthttpcrate to handle other forms of HeaderMap either.