Go to file
Chris Dent 34eb63940d Add a global flag to strictly handle response headers
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
2016-09-27 10:26:28 +01:00
2016-09-22 19:00:13 +01:00
2012-10-02 07:04:33 -07:00
2015-08-12 13:44:44 +01:00
2016-09-22 19:00:13 +01:00
2014-07-19 14:06:56 +01:00
2016-03-18 14:29:47 +00:00
2014-08-06 10:44:02 +01:00
2016-09-23 00:30:22 +01:00

wsgi-intercept

travis

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:

  • urllib2
  • httplib
  • httplib2
  • requests
  • urllib3

In Python 3:

  • urllib.request
  • http.client
  • httplib2
  • requests
  • urllib3

If you are using Python 2 and need support for a different HTTP client, require a version of wsgi_intercept<0.6.

Description
RETIRED, further work has moved to Debian project infrastructure
Readme 271 KiB
Languages
Python 98.6%
Makefile 1.4%