Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1222

Show
Ignore:
Timestamp:
08/05/06 20:03:15
Author:
fumanchu
Message:

Eliminated 'default_content_type' config entry by moving tools.response_headers to on_start_resource. If anyone still needs response headers to be set late, they can call tools.response_headers later, either in code or via a hook declared in config.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cprequest.py

    r1209 r1222  
    632632    """An HTTP Response.""" 
    633633     
     634    # Class attributes for dev-time introspection. 
    634635    status = None 
    635636    header_list = None 
     
    646647         
    647648        self.headers = http.HeaderMap() 
    648         content_type = cherrypy.config.get('default_content_type', 'text/html') 
    649649        # Since we know all our keys are titled strings, we can 
    650650        # bypass HeaderMap.update and get a big speed boost. 
    651651        dict.update(self.headers, { 
    652             "Content-Type": content_type
     652            "Content-Type": 'text/html'
    653653            "Server": "CherryPy/" + cherrypy.__version__, 
    654654            "Date": http.HTTPDate(self.time), 
    655             "Set-Cookie": [], 
    656             "Content-Length": None 
    657655        }) 
    658656        self.simple_cookie = Cookie.SimpleCookie() 
  • trunk/cherrypy/_cptools.py

    r1202 r1222  
    290290default_toolbox.session_auth = MainTool(cptools.session_auth) 
    291291default_toolbox.proxy = Tool('before_request_body', cptools.proxy) 
    292 default_toolbox.response_headers = Tool('before_finalize', cptools.response_headers) 
     292default_toolbox.response_headers = Tool('on_start_resource', cptools.response_headers) 
    293293# We can't call virtual_host in on_start_resource, 
    294294# because it's failsafe and the redirect would be swallowed. 
  • trunk/cherrypy/lib/caching.py

    r1208 r1222  
    196196         
    197197        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" 
    199200            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" 
    201203         
    202204        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  
    100100 
    101101 
    102 def response_headers(headers=None, force=True): 
     102def response_headers(headers=None): 
    103103    """Set headers on the response.""" 
    104104    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 
    107106 
    108107 
  • trunk/cherrypy/test/test_core.py

    r1213 r1222  
    4242        def defct(self, newct): 
    4343            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)]}) 
    4547        defct.exposed = True 
    4648         
  • trunk/cherrypy/test/test_response_headers.py

    r1145 r1222  
    1919        other._cp_config = { 
    2020            'tools.response_headers.on': True, 
    21             'tools.response_headers.force': False, 
    2221            'tools.response_headers.headers': [("Content-Language", "fr"), 
    2322                                               ('Content-Type', 'text/plain')], 
     
    4342        self.getPage('/other') 
    4443        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') 
    5045 
    5146if __name__ == "__main__": 

Hosted by WebFaction

Log in as guest/cpguest to create tickets