Skip to content

Commit f4c1a65

Browse files
committed
on duplicate header: return values as list
Fixes peritus#4
1 parent 39c7423 commit f4c1a65

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/HttpLibrary/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,12 @@ def response_should_not_have_header(self, header_name):
353353
def get_response_header(self, header_name):
354354
"""
355355
Get the response header with the name `header_name`
356+
357+
If there are two headers with the same key, the return value of this
358+
keyword is a list containing both values.
356359
"""
357360
self.response_should_have_header(header_name)
358-
return self.response.headers[header_name]
361+
return self.response.headers.getall(header_name)
359362

360363
def response_header_should_equal(self, header_name, expected):
361364
"""

src/HttpLibrary/livetest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ def _do_httplib_request(self, req):
7676
res = webtest.TestResponse()
7777
res.status = '%s %s' % (webresp.status, webresp.reason)
7878
res.body = webresp.read()
79-
res.headerlist = webresp.getheaders()
79+
response_headers = []
80+
for headername in dict(webresp.getheaders()).keys():
81+
for headervalue in webresp.msg.getheaders(headername):
82+
response_headers.append((headername, headervalue))
83+
res.headerlist = response_headers
8084
res.errors = ''
8185
return res
8286

tests/http/mockserver.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ def do_GET(self):
6868
self.end_headers()
6969
self.wfile.write("***%s***" % self.headers['Host'])
7070
self.finish()
71+
elif self.path == '/duplicate_header':
72+
self.send_response(200, 'OK')
73+
self.send_header('Duplicate', 'Yes')
74+
self.send_header('Duplicate', 'Si!')
75+
self.end_headers()
76+
self.finish()
7177
else:
7278
self.send_error(500)
7379

tests/http/simple.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ HEAD request with User Agent Header
246246
HEAD /
247247
Response Header Should Equal x-request-user-agent MYBROWSER
248248

249+
Test Duplicate Headers
250+
GET /duplicate_header
249251

250-
252+
${x}= Get Response Header Duplicate
253+
Length Should Be ${x} 2
254+
Should Be Equal ${x[0]} Yes
255+
Should Be Equal ${x[1]} Si!
251256

0 commit comments

Comments
 (0)