Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 36e0ee9

Browse files
committed
Allow retrieval of 'raw' headers.
1 parent 721a239 commit 36e0ee9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

hyper/common/headers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ def get(self, name, default=None):
146146
except KeyError:
147147
return default
148148

149+
def iter_raw(self):
150+
"""
151+
Allows iterating over the headers in 'raw' form: that is, the form in
152+
which they were added to the structure. This iteration is in order,
153+
and can be used to rebuild the original headers (e.g. to determine
154+
exactly what a server sent).
155+
"""
156+
for item in self._items:
157+
yield item
158+
149159
def __eq__(self, other):
150160
return self._items == other._items
151161

test/test_headers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,13 @@ def test_create_from_iterables_and_kwargs(self):
203203
h == items + [('k3', 'v4'), ('k4', 'v5')] or
204204
h == items + [('k4', 'v5'), ('k3', 'v4')]
205205
)
206+
207+
def test_raw_iteration(self):
208+
items = [
209+
('k1', 'v2'),
210+
('k2', 'v2, v3, v4'),
211+
('k2', 'v3'),
212+
]
213+
h = HTTPHeaderMap(items)
214+
215+
assert list(h.iter_raw()) == items

0 commit comments

Comments
 (0)