feat(header): change Cookie to be map-like
The `Cookie` header now has 'set' and `get` methods, to treat the list of cookies as a map. Closes #1145 BREAKING CHANGE: The `Cookie` header is no longer a wrapper over a `Vec<String>`. It must be accessed via its `get` and `append` methods.
This commit is contained in:
@@ -19,6 +19,11 @@ impl<K: PartialEq, V> VecMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn append(&mut self, key: K, value: V) {
|
||||
self.vec.push((key, value));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn entry(&mut self, key: K) -> Entry<K, V> {
|
||||
match self.find(&key) {
|
||||
@@ -55,10 +60,23 @@ impl<K: PartialEq, V> VecMap<K, V> {
|
||||
pub fn iter(&self) -> ::std::slice::Iter<(K, V)> {
|
||||
self.vec.iter()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn remove<K2: PartialEq<K> + ?Sized>(&mut self, key: &K2) -> Option<V> {
|
||||
self.find(key).map(|pos| self.vec.remove(pos)).map(|(_, v)| v)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn remove_all<K2: PartialEq<K> + ?Sized>(&mut self, key: &K2) {
|
||||
let len = self.vec.len();
|
||||
for i in (0..len).rev() {
|
||||
if key == &self.vec[i].0 {
|
||||
self.vec.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn clear(&mut self) {
|
||||
self.vec.clear();
|
||||
|
||||
Reference in New Issue
Block a user