Skip to content

Commit cf182f7

Browse files
author
adam
committed
Clean up edge case handling in util.getHeader()
1 parent 695c891 commit cf182f7

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lib/util.py

100644100755
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ def getopts(args, options,
259259

260260

261261
def getHeader(request_or_response, header_name):
262+
if request_or_response == None:
263+
return ''
262264
try:
263265
httpHdr = request_or_response.headers[header_name]
264266
except:
@@ -269,7 +271,10 @@ def getHeader(request_or_response, header_name):
269271
# return unique list joined by ','
270272
return ', '.join(set(httpHdr))
271273
else:
272-
return ''
274+
try:
275+
return unicode(httpHdr).encode('utf-8')
276+
except:
277+
return ''
273278

274279
# HTTPlastmodified - Extracts last-modified (or date) header from
275280
# HTTP response headers and normalizes date string format

0 commit comments

Comments
 (0)