diff --git a/test/test_wsgi_compliance.py b/test/test_wsgi_compliance.py index faf7dab..654b23c 100644 --- a/test/test_wsgi_compliance.py +++ b/test/test_wsgi_compliance.py @@ -50,7 +50,8 @@ def test_more_interesting(): resp, content = http.request( 'http://some_hopefully_nonexistant_domain' + expected_uri, 'GET', - headers={'Accept': 'application/json'}) + headers={'Accept': 'application/json', + 'Cookie': 'foo=bar'}) internal_env = app.get_internals() expected_path_info = unquote(expected_uri.split('?')[0]) @@ -58,6 +59,8 @@ def test_more_interesting(): assert internal_env['RAW_URI'] == expected_uri assert internal_env['QUERY_STRING'] == 'bar=baz%20zoom' assert internal_env['HTTP_ACCEPT'] == 'application/json' + assert internal_env['HTTP_COOKIE'] == 'foo=bar' + assert type(internal_env['HTTP_COOKIE']) == type('') # Do the rather painful wsgi encoding dance. if sys.version_info[0] > 2: diff --git a/wsgi_intercept/__init__.py b/wsgi_intercept/__init__.py index 6e20744..3ad0a86 100644 --- a/wsgi_intercept/__init__.py +++ b/wsgi_intercept/__init__.py @@ -220,7 +220,11 @@ def make_environ(inp, host, port, script_name): k, v = line.strip().split(b':', 1) v = v.lstrip() - v = v.decode('ISO-8859-1') + # Make header value a "native" string. PEP 3333 requires that + # string-like things in headers be of type `str`. Much of the + # time this isn't a problem but the SimpleCookie library does + # type checking against `type("")`. + v = str(v.decode('ISO-8859-1')) # # take care of special headers, and for the rest, put them