34eb63940db055d15aaf801fac46b6459f04f1cc
According to pep 3333 response headers are supposed to be bytestrings. In Python 2 that means a str, and in Python 3, bytes. Some wsgi servers, notably mod_wsgi, check that the values of headers are correct, and make an error if they are not. In at least some testing situations wsgi-intercept should replicate this behavior so that an application can know that it is not sending bad headers. This is something that needs to be done in wsgi_intercept itself, and not external tests, because many http client libraries will transform response header values to native strings before providing them to the caller. However, many existing tools (for example selector) do not obey this constraint, so we cannot simply turn this check on by default. Instead we need to be able to declare that for a given context we want it to be done. The easiest way to do this is to set a module level global, as done in wsgi_intercept/tests/__init__.py. In practical terms what this code does, is disallow * in py2, sending responses with unicode values * in py3, sending responses with str values if wsgi_intercept.STRICT_RESPONSE_HEADERS == True. Because this change introduced some six into wsgi_intercept/__init__.py, additional changes to use six were made. Note that since Python 2.7 io.BytesIO has been available so we no longer need to do a conditional import. Interestingly, some testing suggests that six.BytesIO in 2.7 is _not_ the same as io.BytesIO. Fixes: #43
wsgi-intercept
Documentation is available on Read The Docs.
What is it?
wsgi_intercept installs a WSGI application in place of a real host for testing while still preserving HTTP semantics. See the PyPI page page for more details. It works by intercepting the connection handling in http client libraries.
Supported Libraries
For Python 2.7 the following libraries are supported:
urllib2httplibhttplib2requestsurllib3
In Python 3:
urllib.requesthttp.clienthttplib2requestsurllib3
If you are using Python 2 and need support for a different HTTP
client, require a version of wsgi_intercept<0.6.
Description
Languages
Python
98.6%
Makefile
1.4%
