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

Changeset 1051

Show
Ignore:
Timestamp:
04/21/06 16:42:11
Author:
fumanchu
Message:

Added a 'force' flag to response_headers tool.

Files:

Legend:

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

    r1049 r1051  
    205205 
    206206 
    207 def response_headers(headers=None): 
     207def response_headers(headers=None, force=True): 
    208208    """Set headers on the response.""" 
    209     for name, value in headers or []
    210         if name not in cherrypy.response.headers
     209    for name, value in (headers or [])
     210        if force or (name not in cherrypy.response.headers)
    211211            cherrypy.response.headers[name] = value 
    212212 
  • trunk/cherrypy/test/test_response_headers_filter.py

    r1049 r1051  
    2323        '/other': { 
    2424            'tools.response_headers.on': True, 
     25            'tools.response_headers.force': False, 
    2526            'tools.response_headers.headers': [("Content-Language", "fr"), 
    26                                                ('Content-Type', 'text/plain')] 
     27                                               ('Content-Type', 'text/plain')], 
    2728            }, 
    2829        }) 
     
    4142        self.getPage('/other') 
    4243        self.assertHeader("Content-Language", "fr") 
    43         # the filter should only change headers that have not been set yet 
     44        # Since 'force' is False, the filter should only change headers 
     45        # that have not been set yet. 
    4446        # Content-Type should have been set when the response object 
    4547        # was created (default to text/html) 

Hosted by WebFaction

Log in as guest/cpguest to create tickets