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'
>>> @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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
wsgiheaders-0.2.zip
(5.5 kB
view details)
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
wsgiheaders-0.2.win32.exe
(71.1 kB
view details)
wsgiheaders-0.2-py2.6.egg
(5.2 kB
view details)
File details
Details for the file wsgiheaders-0.2.zip.
File metadata
- Download URL: wsgiheaders-0.2.zip
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3912aa2771a88396442e3b1f49b2b59431eb987fe9dc2f5791a609e515c2618
|
|
| MD5 |
e50b0835530eeef7ea0e364f12dad813
|
|
| BLAKE2b-256 |
eaefcf0e50316cb63bcdc876ed2ae78b67d3dcb711442a7532ff3f22838e6ba0
|
File details
Details for the file wsgiheaders-0.2.win32.exe.
File metadata
- Download URL: wsgiheaders-0.2.win32.exe
- Upload date:
- Size: 71.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9dc27f021be99ced9d4127abbad46cb709f3297ef67d893e14fecfabf3c1030
|
|
| MD5 |
623a614b9add0c30ff43d4dc4ec0e6c2
|
|
| BLAKE2b-256 |
bbf3468e52d282fe024e5fcab6c9c15f9e46a502cfc60d758774ec4e51eca420
|
File details
Details for the file wsgiheaders-0.2-py2.6.egg.
File metadata
- Download URL: wsgiheaders-0.2-py2.6.egg
- Upload date:
- Size: 5.2 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c687b0bad1a4cb55de71b87c5199b080d1423d782ee26ec8da87059da9ad596a
|
|
| MD5 |
99577388604a56a20c8b476010638b9b
|
|
| BLAKE2b-256 |
39c72f3fa674825ff7439a68de0557aa091deecc22ec4ffb8baad4c821eb1088
|