Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare v0.2.11 #643

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.2.11 (November 13, 2023)

* Fix MIRI error in `header::Iter`.

# 0.2.10 (November 10, 2023)

* Fix parsing of `Authority` to handle square brackets in incorrect order.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = "http"
# - Update html_root_url in lib.rs.
# - Update CHANGELOG.md.
# - Create git tag
version = "0.2.10"
version = "0.2.11"
readme = "README.md"
documentation = "https://docs.rs/http"
repository = "https://github.com/hyperium/http"
Expand Down
55 changes: 44 additions & 11 deletions src/header/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ pub struct HeaderMap<T = HeaderValue> {
/// more than once if it has more than one associated value.
#[derive(Debug)]
pub struct Iter<'a, T> {
inner: IterMut<'a, T>,
map: &'a HeaderMap<T>,
entry: usize,
cursor: Option<Cursor>,
}

/// `HeaderMap` mutable entry iterator
Expand Down Expand Up @@ -811,12 +813,9 @@ impl<T> HeaderMap<T> {
/// ```
pub fn iter(&self) -> Iter<'_, T> {
Iter {
inner: IterMut {
map: self as *const _ as *mut _,
entry: 0,
cursor: self.entries.first().map(|_| Cursor::Head),
lt: PhantomData,
},
map: self,
entry: 0,
cursor: self.entries.first().map(|_| Cursor::Head),
}
}

Expand Down Expand Up @@ -2078,13 +2077,47 @@ impl<'a, T> Iterator for Iter<'a, T> {
type Item = (&'a HeaderName, &'a T);

fn next(&mut self) -> Option<Self::Item> {
self.inner
.next_unsafe()
.map(|(key, ptr)| (key, unsafe { &*ptr }))
use self::Cursor::*;

if self.cursor.is_none() {
if (self.entry + 1) >= self.map.entries.len() {
return None;
}

self.entry += 1;
self.cursor = Some(Cursor::Head);
}

let entry = &self.map.entries[self.entry];

match self.cursor.unwrap() {
Head => {
self.cursor = entry.links.map(|l| Values(l.next));
Some((&entry.key, &entry.value))
}
Values(idx) => {
let extra = &self.map.extra_values[idx];

match extra.next {
Link::Entry(_) => self.cursor = None,
Link::Extra(i) => self.cursor = Some(Values(i)),
}

Some((&entry.key, &extra.value))
}
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
let map = self.map;
debug_assert!(map.entries.len() >= self.entry);

let lower = map.entries.len() - self.entry;
// We could pessimistically guess at the upper bound, saying
// that its lower + map.extra_values.len(). That could be
// way over though, such as if we're near the end, and have
// already gone through several extra values...
(lower, None)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc(html_root_url = "https://docs.rs/http/0.2.10")]
#![doc(html_root_url = "https://docs.rs/http/0.2.11")]

//! A general purpose library of common HTTP types
//!
Expand Down
1 change: 1 addition & 0 deletions tests/header_map_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rand::{Rng, SeedableRng};

use std::collections::HashMap;

#[cfg(not(miri))]
#[test]
fn header_map_fuzz() {
fn prop(fuzz: Fuzz) -> TestResult {
Expand Down