Skip to main content

Adding and replacing response headers

Project description

Adding and replacing response headers

>>> @replaceheader([(r'.*\.html', [('Content-type', 'text/html')])])
... def app(environ, start_response):
... start_response('200 OK',
... [('Content-type', 'text/plain')])
... return ['Hello, world!']
>>> import webtest
>>> app = webtest.TestApp(app)
>>> res = app.get('/a.txt')
>>> res.content_type
'text/plain'
>>> res = app.get('/a.html')
>>> res.content_type
'text/html'
>>> def xrds(environ):
... return [('X-XRDS', environ['wsgi.url_scheme'] + '://' +
environ['SERVER_NAME'] + '/svc.xrds')]
...
>>> def predicate(environ):
... return environ.get('HTTP_ACCEPT', '').find('application/xrds+xml') != -
1
...
>>> @addheader([(predicate, xrds)])
... def app(environ, start_response):
... start_response('200 OK',
... [('Content-type', 'text/plain')])
... return ['Hello, world!']
>>> app = webtest.TestApp(app)
>>> res = app.get('/')
>>> 'X-XRDS' in res.headers
False
>>> res = app.get('/', headers={'Accept':'application/xrds+xml'})
>>> res.headers['X-XRDS']
'http://localhost/svc.xrds'

Project details


Release history Release notifications

This version
History Node

0.2

History Node

0.1

History Node

0.0.1

History Node

0.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
wsgiheaders-0.2-py2.6.egg (5.2 kB) Copy SHA256 hash SHA256 Egg 2.6 Jan 11, 2009
wsgiheaders-0.2.win32.exe (71.1 kB) Copy SHA256 hash SHA256 Windows Installer any Jan 11, 2009
wsgiheaders-0.2.zip (5.5 kB) Copy SHA256 hash SHA256 Source None Jan 11, 2009

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page