Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 098390f

Browse files
committed
Fix RequestHeaders to proper concat repeats
Previously RequestHeaders only provided the last instance of a repeated header.
1 parent f76e534 commit 098390f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

wptserve/request.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,23 @@ def auth(self):
348348
class RequestHeaders(dict):
349349
"""Dictionary-like API for accessing request headers."""
350350
def __init__(self, items):
351-
for key, value in zip(items.keys(), items.values()):
352-
key = key.lower()
353-
if key in self:
354-
self[key].append(value)
351+
for header in items.keys():
352+
key = header.lower()
353+
# if there are other headers with this name, we need them
354+
values = items.getallmatchingheaders(header)
355+
if len(values) > 1:
356+
# collect the multiple variations of the current header
357+
multiples = []
358+
# loop through the values from getallmatchingheaders
359+
for value in values:
360+
if ':' in value:
361+
# split the raw header on the first `:`
362+
# and add that to our list
363+
multiples.append(value.split(':', 1)[1].strip())
364+
dict.__setitem__(self, key, multiples)
355365
else:
356-
dict.__setitem__(self, key, [value])
366+
# adds the last header with this name
367+
dict.__setitem__(self, key, [items[header]])
357368

358369
def __getitem__(self, key):
359370
"""Get all headers of a certain (case-insensitive) name. If there is

0 commit comments

Comments
 (0)