Changeset 1222
- Timestamp:
- 08/05/06 20:03:15
- Files:
-
- trunk/cherrypy/_cprequest.py (modified) (2 diffs)
- trunk/cherrypy/_cptools.py (modified) (1 diff)
- trunk/cherrypy/lib/caching.py (modified) (1 diff)
- trunk/cherrypy/lib/cptools.py (modified) (1 diff)
- trunk/cherrypy/test/test_core.py (modified) (1 diff)
- trunk/cherrypy/test/test_response_headers.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cprequest.py
r1209 r1222 632 632 """An HTTP Response.""" 633 633 634 # Class attributes for dev-time introspection. 634 635 status = None 635 636 header_list = None … … 646 647 647 648 self.headers = http.HeaderMap() 648 content_type = cherrypy.config.get('default_content_type', 'text/html')649 649 # Since we know all our keys are titled strings, we can 650 650 # bypass HeaderMap.update and get a big speed boost. 651 651 dict.update(self.headers, { 652 "Content-Type": content_type,652 "Content-Type": 'text/html', 653 653 "Server": "CherryPy/" + cherrypy.__version__, 654 654 "Date": http.HTTPDate(self.time), 655 "Set-Cookie": [],656 "Content-Length": None657 655 }) 658 656 self.simple_cookie = Cookie.SimpleCookie() trunk/cherrypy/_cptools.py
r1202 r1222 290 290 default_toolbox.session_auth = MainTool(cptools.session_auth) 291 291 default_toolbox.proxy = Tool('before_request_body', cptools.proxy) 292 default_toolbox.response_headers = Tool(' before_finalize', cptools.response_headers)292 default_toolbox.response_headers = Tool('on_start_resource', cptools.response_headers) 293 293 # We can't call virtual_host in on_start_resource, 294 294 # because it's failsafe and the redirect would be swallowed. trunk/cherrypy/lib/caching.py
r1208 r1222 196 196 197 197 if secs == 0: 198 cptools.response_headers([("Pragma", "no-cache")], force) 198 if force or "Pragma" not in cherrypy.response.headers: 199 cherrypy.response.headers["Pragma"] = "no-cache" 199 200 if cherrypy.request.version >= (1, 1): 200 cptools.response_headers([("Cache-Control", "no-cache")], force) 201 if force or "Cache-Control" not in cherrypy.response.headers: 202 cherrypy.response.headers["Cache-Control"] = "no-cache" 201 203 202 204 expiry = http.HTTPDate(cherrypy.response.time + secs) 203 cptools.response_headers([("Expires", expiry)], force) 205 if force or "Expires" not in cherrypy.response.headers: 206 cherrypy.response.headers["Expires"] = expiry trunk/cherrypy/lib/cptools.py
r1203 r1222 100 100 101 101 102 def response_headers(headers=None , force=True):102 def response_headers(headers=None): 103 103 """Set headers on the response.""" 104 104 for name, value in (headers or []): 105 if force or (name not in cherrypy.response.headers): 106 cherrypy.response.headers[name] = value 105 cherrypy.response.headers[name] = value 107 106 108 107 trunk/cherrypy/test/test_core.py
r1213 r1222 42 42 def defct(self, newct): 43 43 newct = "text/%s" % newct 44 cherrypy.config.update({'default_content_type': newct}) 44 cherrypy.config.update({'tools.response_headers.on': True, 45 'tools.response_headers.headers': 46 [('Content-Type', newct)]}) 45 47 defct.exposed = True 46 48 trunk/cherrypy/test/test_response_headers.py
r1145 r1222 19 19 other._cp_config = { 20 20 'tools.response_headers.on': True, 21 'tools.response_headers.force': False,22 21 'tools.response_headers.headers': [("Content-Language", "fr"), 23 22 ('Content-Type', 'text/plain')], … … 43 42 self.getPage('/other') 44 43 self.assertHeader("Content-Language", "fr") 45 # Since 'force' is False, the tool should only change headers 46 # that have not been set yet. 47 # Content-Type should have been set when the response object 48 # was created (default to text/html) 49 self.assertHeader('Content-Type', 'text/html') 44 self.assertHeader('Content-Type', 'text/plain') 50 45 51 46 if __name__ == "__main__":

