/usr/share/pyshared/cherrypy/test/test_response_headers_filter.py is in python-cherrypy 2.3.0-3build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import test
test.prefer_parent_path()
import cherrypy
from cherrypy._cputil import headers
def setup_server():
class Root:
def index(self):
yield "Hello, world"
index = headers([("Content-Language", "en-GB"),
('Content-Type', 'text/plain')])(index)
index.exposed = True
def other(self):
return "salut"
other.exposed = True
cherrypy.root = Root()
cherrypy.config.update({
'/other': {
'response_headers_filter.on': True,
'response_headers_filter.headers': [("Content-Language", "fr"),
('Content-Type', 'text/plain')]
},
})
import helper
class ResponseHeadersFilterTest(helper.CPWebCase):
def testResponseHeadersDecorator(self):
self.getPage('/')
self.assertHeader("Content-Language", "en-GB")
self.assertHeader('Content-Type', 'text/plain')
def testResponseHeadersFilter(self):
self.getPage('/other')
self.assertHeader("Content-Language", "fr")
# the filter should only change headers that have not been set yet
# Content-Type should have been set when the response object
# was created (default to text/html)
self.assertHeader('Content-Type', 'text/html')
if __name__ == "__main__":
setup_server()
helper.testmain()
|