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

Fix RequestHeaders to proper concat repeats #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 15 additions & 5 deletions wptserve/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,22 @@ def auth(self):
class RequestHeaders(dict):
"""Dictionary-like API for accessing request headers."""
def __init__(self, items):
for key, value in zip(items.keys(), items.values()):
key = key.lower()
if key in self:
self[key].append(value)
for header in items.keys():
key = header.lower()
# if there are other headers with this name, we need them
values = items.getallmatchingheaders(header)
if len(values) > 1:
# collect the multiple variations of the current header
multiples = []
# loop through the values from getallmatchingheaders
for value in values:
# split the raw header on the first `:`
# and add that to our list
multiples.append(value.split(':', 1)[1].strip())
dict.__setitem__(self, key, multiples)
else:
dict.__setitem__(self, key, [value])
# adds the last header with this name
dict.__setitem__(self, key, [items[header]])

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