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

Commit

Permalink
Fix RequestHeaders to proper concat repeats
Browse files Browse the repository at this point in the history
Previously RequestHeaders only provided the last instance
of a repeated header.
  • Loading branch information
BigBlueHat committed Jul 28, 2016
1 parent f76e534 commit 098390f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions wptserve/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,23 @@ 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:
if ':' in value:
# 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

0 comments on commit 098390f

Please sign in to comment.