From 098390f1f553f47f2b73b969ff354ea07c685544 Mon Sep 17 00:00:00 2001 From: BigBlueHat Date: Thu, 28 Jul 2016 19:54:46 -0400 Subject: [PATCH] Fix RequestHeaders to proper concat repeats Previously RequestHeaders only provided the last instance of a repeated header. --- wptserve/request.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/wptserve/request.py b/wptserve/request.py index b12b4b8..45d5d48 100644 --- a/wptserve/request.py +++ b/wptserve/request.py @@ -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