Adding and replacing response headers
Project description
Adding and replacing response headers >>> import re >>> p = re.compile(r’.*.html’) >>> @replaceheader([(p, [(‘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’ >>> p = re.compile(r’.*’) >>> @addheader([(p, [(‘X-XRDS’, ‘http://localhost/services.xrds’)])]) … def app(environ, start_response): … start_response(‘200 OK’, … [(‘Content-type’, ‘text/plain’)]) … return [‘Hello, world!’] >>> app = webtest.TestApp(app) >>> res = app.get(‘/’) >>> res.headers[‘X-XRDS’] ‘http://localhost/services.xrds’
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.