Skip to content

fix: correct HeaderMap iterators' len and size_hint for multi-value#3971

Merged
robjtede merged 2 commits intomainfrom
fix-3969
Mar 10, 2026
Merged

fix: correct HeaderMap iterators' len and size_hint for multi-value#3971
robjtede merged 2 commits intomainfrom
fix-3969

Conversation

@robjtede
Copy link
Member

PR Type

Fix

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt.
  • (Team) Label with affected crates and semver status.

Overview

Fixes #3969

@github-actions github-actions bot added the A-http project: actix-http label Mar 10, 2026
@robjtede robjtede added B-semver-patch and removed A-http project: actix-http labels Mar 10, 2026
@robjtede robjtede enabled auto-merge March 10, 2026 04:35
@robjtede robjtede changed the title Fix 3969 fix: correct HeaderMap iterators' len and size_hint for multi-value Mar 10, 2026
@robjtede robjtede requested a review from JohnTitor March 10, 2026 06:05
/// ```
pub fn iter(&self) -> Iter<'_> {
Iter::new(self.inner.iter())
Iter::new(self.inner.iter(), self.len())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-existing but len() does a bit more work than usual:

self.inner.values().map(|vals| vals.len()).sum()

I'm not sure how its full scan affects performance, but I guess we could inline the length inside map 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ye i was thinking about that too, good optimisation target for another PR

Copy link
Member

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with or without addressing my comment.

@robjtede robjtede added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit 79434bd Mar 10, 2026
23 of 24 checks passed
@robjtede robjtede deleted the fix-3969 branch March 10, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HeaderMap iterators violate ExactSizeIterator for multi-value headers and panic on .len()

2 participants