skip to navigation
skip to content

wsgiheaders 0.2

Adding and replacing response headers

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'
File Type Py Version Uploaded on Size # downloads
wsgiheaders-0.2-py2.6.egg (md5) Python Egg 2.6 2009-01-11 20:08:50 5KB 120
wsgiheaders-0.2.win32.exe (md5) MS Windows installer any 2009-01-11 20:08:52 69KB 17
wsgiheaders-0.2.zip (md5) Source 2009-01-11 20:08:55 5KB 75

Log in to rate this package.