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'
>>> @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'
Release files for wsgiheaders 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wsgiheaders-0.2.zip | 5.5 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wsgiheaders-0.2.win32.exe | Details | |||
| wsgiheaders-0.2-py2.6.egg | Legacy Egg format | - | - | Details |
Total release size: 81.7 kB
Release files / wsgiheaders-0.2.zip
| Download URL | wsgiheaders-0.2.zip |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a3912aa2771a88396442e3b1f49b2b59431eb987fe9dc2f5791a609e515c2618
|
|
BLAKE2b-256 checksum How to use checksums |
eaefcf0e50316cb63bcdc876ed2ae78b67d3dcb711442a7532ff3f22838e6ba0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / wsgiheaders-0.2.win32.exe
| Download URL | wsgiheaders-0.2.win32.exe |
|---|---|
| Size | 71.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9dc27f021be99ced9d4127abbad46cb709f3297ef67d893e14fecfabf3c1030
|
|
BLAKE2b-256 checksum How to use checksums |
bbf3468e52d282fe024e5fcab6c9c15f9e46a502cfc60d758774ec4e51eca420
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / wsgiheaders-0.2-py2.6.egg
| Download URL | wsgiheaders-0.2-py2.6.egg |
|---|---|
| Size | 5.2 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
c687b0bad1a4cb55de71b87c5199b080d1423d782ee26ec8da87059da9ad596a
|
|
BLAKE2b-256 checksum How to use checksums |
39c72f3fa674825ff7439a68de0557aa091deecc22ec4ffb8baad4c821eb1088
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |