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

Changeset 1402

Show
Ignore:
Timestamp:
10/20/06 02:14:06
Author:
fumanchu
Message:

Trunk fix for #577 (GzipFilter doesn't force an update of the Content-Length header). All code which could change the length of response.body should delete the Content-Length header (if already set).

Files:

Legend:

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

    r1369 r1402  
    211211            body = self.login_screen(from_page, username, error_msg) 
    212212            cherrypy.response.body = body 
     213            if cherrypy.response.headers.has_key("Content-Length"): 
     214                # Delete Content-Length header so finalize() recalcs it. 
     215                del cherrypy.response.headers["Content-Length"] 
    213216            return True 
    214217        else: 
     
    236239        if not username: 
    237240            cherrypy.response.body = self.login_screen(cherrypy.url(qs=request.query_string)) 
     241            if cherrypy.response.headers.has_key("Content-Length"): 
     242                # Delete Content-Length header so finalize() recalcs it. 
     243                del cherrypy.response.headers["Content-Length"] 
    238244            return True 
    239245         
  • trunk/cherrypy/lib/encoding.py

    r1391 r1402  
    101101        response.collapse_body() 
    102102        encoder = encode_string 
     103        if response.headers.has_key("Content-Length"): 
     104            # Delete Content-Length header so finalize() recalcs it. 
     105            # Encoded strings may be of different lengths from their 
     106            # unicode equivalents, and even from each other. For example: 
     107            # >>> t = u"\u7007\u3040" 
     108            # >>> len(t) 
     109            # 2 
     110            # >>> len(t.encode("UTF-8")) 
     111            # 6 
     112            # >>> len(t.encode("utf7")) 
     113            # 8 
     114            del response.headers["Content-Length"] 
    103115     
    104116    # Parse the Accept-Charset request header, and try to provide one 
     
    218230                response.headers['Content-Encoding'] = 'gzip' 
    219231                response.body = compress(response.body, compress_level) 
     232                if response.headers.has_key("Content-Length"): 
     233                    # Delete Content-Length header so finalize() recalcs it. 
     234                    del response.headers["Content-Length"] 
    220235            return 
    221236    cherrypy.HTTPError(406, "identity, gzip").set_response() 
  • trunk/cherrypy/lib/static.py

    r1401 r1402  
    1818    """Set status, headers, and body in order to serve the given file. 
    1919     
    20     The Content-Type header will be set to the content_ype arg, if provided. 
     20    The Content-Type header will be set to the content_type arg, if provided. 
    2121    If not provided, the Content-Type will be guessed by its extension. 
    2222     
     
    9797                ct = "multipart/byteranges; boundary=%s" % boundary 
    9898                response.headers['Content-Type'] = ct 
    99 ##                del response.headers['Content-Length'] 
     99                if response.headers.has_key("Content-Length"): 
     100                    # Delete Content-Length header so finalize() recalcs it. 
     101                    del response.headers["Content-Length"] 
    100102                 
    101103                def file_ranges(): 
  • trunk/cherrypy/lib/tidy.py

    r1313 r1402  
    1919    server would also crash) 
    2020    """ 
     21    response = cherrypy.response 
     22     
    2123    # the tidy tool, by its very nature it's not generator friendly,  
    2224    # so we just collapse the body and work with it. 
    23     orig_body = cherrypy.response.collapse_body() 
     25    orig_body = response.collapse_body() 
    2426     
    25     fct = cherrypy.response.headers.get('Content-Type', '') 
     27    fct = response.headers.get('Content-Type', '') 
    2628    ct = fct.split(';')[0] 
    2729    encoding = '' 
     
    7476         
    7577        if new_errs: 
    76             cherrypy.response.body = wrong_content('<br />'.join(new_errs), 
    77                                                    orig_body) 
     78            response.body = wrong_content('<br />'.join(new_errs), orig_body) 
     79            if response.headers.has_key("Content-Length"): 
     80                # Delete Content-Length header so finalize() recalcs it. 
     81                del response.headers["Content-Length"] 
    7882            return 
    7983        elif strict_xml: 
     
    97101                traceback.print_exc(file = body_file) 
    98102                body_file = '<br />'.join(body_file.getvalue()) 
    99                 cherrypy.response.body = wrong_content(body_file, orig_body, "XML") 
     103                response.body = wrong_content(body_file, orig_body, "XML") 
     104                if response.headers.has_key("Content-Length"): 
     105                    # Delete Content-Length header so finalize() recalcs it. 
     106                    del response.headers["Content-Length"] 
    100107                return 
    101108         
    102109        if use_output: 
    103             cherrypy.response.body = [output] 
     110            response.body = [output] 
     111            if response.headers.has_key("Content-Length"): 
     112                # Delete Content-Length header so finalize() recalcs it. 
     113                del response.headers["Content-Length"] 
    104114 
    105115def html_space(text): 
     
    119129 
    120130def nsgmls(temp_dir, nsgmls_path, catalog_path, errors_to_ignore=None): 
     131    response = cherrypy.response 
     132     
    121133    # the tidy tool, by its very nature it's not generator friendly,  
    122134    # so we just collect the body and work with it. 
    123     orig_body = cherrypy.response.collapse_body() 
     135    orig_body = response.collapse_body() 
    124136     
    125     fct = cherrypy.response.headers.get('Content-Type', '') 
     137    fct = response.headers.get('Content-Type', '') 
    126138    ct = fct.split(';')[0] 
    127139    encoding = '' 
     
    163175         
    164176        if new_errs: 
    165             cherrypy.response.body = wrong_content('<br />'.join(new_errs), 
    166                                                    orig_body) 
     177            response.body = wrong_content('<br />'.join(new_errs), orig_body) 
     178            if response.headers.has_key("Content-Length"): 
     179                # Delete Content-Length header so finalize() recalcs it. 
     180                del response.headers["Content-Length"] 
    167181 

Hosted by WebFaction

Log in as guest/cpguest to create tickets