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

Changeset 771

Show
Ignore:
Timestamp:
10/31/05 15:52:35
Author:
fumanchu
Message:

Fix for #367 (error pages should reset response headers). And a new _cpOnHTTPError special attribute just for kicks.

Files:

Legend:

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

    r770 r771  
    164164    def set_response(self): 
    165165        import cherrypy 
    166         from cherrypy._cputil import getErrorPage, formatExc 
    167          
    168         tb = formatExc() 
    169         if cherrypy.config.get('server.logTracebacks', True): 
    170             cherrypy.log(tb) 
    171          
    172         if not cherrypy.config.get('server.showTracebacks', False): 
    173             tb = None 
    174          
    175         # In all cases, finalize will be called after this method, 
    176         # so don't bother cleaning up response values here. 
    177         cherrypy.response.status = self.status 
    178         cherrypy.response.body = getErrorPage(self.status, traceback=tb, 
    179                                               message=self.message) 
    180          
    181         if cherrypy.response.headerMap.has_key("Content-Encoding"): 
    182             del cherrypy.response.headerMap['Content-Encoding'] 
     166        handler = cherrypy._cputil.getSpecialAttribute("_cpOnHTTPError") 
     167        handler(self.status, self.message) 
    183168 
    184169 
     
    199184    def __init__(self, message=None): 
    200185        HTTPError.__init__(self, 500, message) 
     186 
  • trunk/cherrypy/_cputil.py

    r768 r771  
    191191     
    192192    return template % kwargs 
     193 
     194def _cpOnHTTPError(status, message): 
     195    """ Default _cpOnHTTPError method. 
     196     
     197    status should be an int. 
     198    """ 
     199    tb = formatExc() 
     200    if cherrypy.config.get('server.logTracebacks', True): 
     201        cherrypy.log(tb) 
     202     
     203    if not cherrypy.config.get('server.showTracebacks', False): 
     204        tb = None 
     205     
     206    response = cherrypy.response 
     207     
     208    # Remove headers which applied to the original content, 
     209    # but do not apply to the error page. 
     210    for key in ["Accept-Ranges", "Age", "ETag", "Location", 
     211                "Retry-After", "Vary", "Content-Encoding", 
     212                "Content-Length", "Content-Location", "Content-MD5", 
     213                "Expires", "Last-Modified"]: 
     214        if response.headerMap.has_key(key): 
     215            del response.headerMap[key] 
     216     
     217    if status != 416: 
     218        # A server sending a response with status code 416 (Requested 
     219        # range not satisfiable) SHOULD include a Content-Range field 
     220        # with a byte-range- resp-spec of "*". The instance-length 
     221        # specifies the current length of the selected resource. 
     222        # A response with status code 206 (Partial Content) MUST NOT 
     223        # include a Content-Range field with a byte-range- resp-spec of "*". 
     224        if response.headerMap.has_key("Content-Range"): 
     225            del response.headerMap["Content-Range"] 
     226     
     227    # In all cases, finalize will be called after this method, 
     228    # so don't bother cleaning up response values here. 
     229    response.status = status 
     230    response.headerMap['Content-Type'] = "text/html" 
     231    response.body = getErrorPage(status, traceback=tb, message=message) 
    193232 
    194233def formatExc(exc=None): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets