Enforce that header names and values are bytes

This commit is contained in:
Andrew Godwin 2018-05-24 12:31:18 +02:00 committed by Andrew Godwin
parent dd2c8b2a0f
commit b3c097aabd

View File

@ -45,6 +45,10 @@ def parse_x_forwarded_for(headers,
# Lowercase all header names in the dict
headers = {name.lower(): values for name, values in headers.items()}
# Make sure header names and values are bytes
assert all(isinstance(name, bytes) for name in headers.keys())
assert all(isinstance(value, bytes) for value in headers.values())
address_header_name = address_header_name.lower().encode("utf-8")
result = original
if address_header_name in headers: