Skip to content

Commit 84ea9e7

Browse files
http: Replace header::map::GetAll with std::slice::Iter (#2527)
1 parent 0bd5ccc commit 84ea9e7

3 files changed

Lines changed: 11 additions & 50 deletions

File tree

‎actix-http/CHANGES.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changes
22

33
## Unreleased - 2021-xx-xx
4+
### Removed
5+
* `header::map::GetAll` iterator, its `Iterator::size_hint` method was wrongly implemented. Replaced with `std::slice::Iter`. [#2527]
6+
7+
[#2527]: https://github.com/actix/actix-web/pull/2527
48

59

610
## 3.0.0-beta.16 - 2021-12-17

‎actix-http/src/header/map.rs‎

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,11 @@ impl HeaderMap {
306306
/// assert_eq!(set_cookies_iter.next().unwrap(), "two=2");
307307
/// assert!(set_cookies_iter.next().is_none());
308308
/// ```
309-
pub fn get_all(&self, key: impl AsHeaderName) -> GetAll<'_> {
310-
GetAll::new(self.get_value(key))
309+
pub fn get_all(&self, key: impl AsHeaderName) -> std::slice::Iter<'_, HeaderValue> {
310+
match self.get_value(key) {
311+
Some(value) => value.iter(),
312+
None => (&[]).iter(),
313+
}
311314
}
312315

313316
// TODO: get_all_mut ?
@@ -602,52 +605,6 @@ impl<'a> IntoIterator for &'a HeaderMap {
602605
}
603606
}
604607

605-
/// Iterator over borrowed values with the same associated name.
606-
///
607-
/// See [`HeaderMap::get_all`].
608-
#[derive(Debug)]
609-
pub struct GetAll<'a> {
610-
idx: usize,
611-
value: Option<&'a Value>,
612-
}
613-
614-
impl<'a> GetAll<'a> {
615-
fn new(value: Option<&'a Value>) -> Self {
616-
Self { idx: 0, value }
617-
}
618-
}
619-
620-
impl<'a> Iterator for GetAll<'a> {
621-
type Item = &'a HeaderValue;
622-
623-
fn next(&mut self) -> Option<Self::Item> {
624-
let val = self.value?;
625-
626-
match val.get(self.idx) {
627-
Some(val) => {
628-
self.idx += 1;
629-
Some(val)
630-
}
631-
None => {
632-
// current index is none; remove value to fast-path future next calls
633-
self.value = None;
634-
None
635-
}
636-
}
637-
}
638-
639-
fn size_hint(&self) -> (usize, Option<usize>) {
640-
match self.value {
641-
Some(val) => (val.len(), Some(val.len())),
642-
None => (0, Some(0)),
643-
}
644-
}
645-
}
646-
647-
impl ExactSizeIterator for GetAll<'_> {}
648-
649-
impl iter::FusedIterator for GetAll<'_> {}
650-
651608
/// Iterator over removed, owned values with the same associated name.
652609
///
653610
/// Returned from methods that remove or replace items. See [`HeaderMap::insert`]
@@ -895,7 +852,7 @@ mod tests {
895852

896853
assert_impl_all!(HeaderMap: IntoIterator);
897854
assert_impl_all!(Keys<'_>: Iterator, ExactSizeIterator, FusedIterator);
898-
assert_impl_all!(GetAll<'_>: Iterator, ExactSizeIterator, FusedIterator);
855+
assert_impl_all!(std::slice::Iter<'_, HeaderValue>: Iterator, ExactSizeIterator, FusedIterator);
899856
assert_impl_all!(Removed: Iterator, ExactSizeIterator, FusedIterator);
900857
assert_impl_all!(Iter<'_>: Iterator, ExactSizeIterator, FusedIterator);
901858
assert_impl_all!(IntoIter: Iterator, ExactSizeIterator, FusedIterator);

‎src/response/response.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl Future for HttpResponse<BoxBody> {
313313

314314
#[cfg(feature = "cookies")]
315315
pub struct CookieIter<'a> {
316-
iter: header::map::GetAll<'a>,
316+
iter: std::slice::Iter<'a, HeaderValue>,
317317
}
318318

319319
#[cfg(feature = "cookies")]

0 commit comments

Comments
 (0)