Robert Brewer avatar Robert Brewer committed 914c10b

2.x backport of [1402]; fix for #577 (GzipFilter doesn't force an update of the Content-Length header)). Also fixes #617.

Comments (0)

Files changed (6)

cherrypy/filters/encodingfilter.py

                 chunk = chunk.encode(encoding, errors)
             body.append(chunk)
         cherrypy.response.body = body
+        # Delete Content-Length header so finalize() recalcs it.
+        cherrypy.response.headers.pop("Content-Length", None)
     except (LookupError, UnicodeError):
         return False
     else:

cherrypy/filters/gzipfilter.py

             response.headers['Content-Encoding'] = 'gzip'
             level = cherrypy.config.get('gzip_filter.compresslevel', 9)
             response.body = self.zip_body(response.body, level)
+            # Delete Content-Length header so finalize() recalcs it.
+            response.headers.pop("Content-Length", None)
         
         acceptable = cherrypy.request.headers.elements('Accept-Encoding')
         if not acceptable:

cherrypy/filters/logdebuginfofilter.py

                 debuginfo += '-->'
             
             cherrypy.response.body = [body, debuginfo]
+            # Delete Content-Length header so finalize() recalcs it.
+            cherrypy.response.headers.pop("Content-Length", None)

cherrypy/filters/nsgmlsfilter.py

                     new_body += "%03d - "%i + cgi.escape(line).replace('\t','    ').replace(' ','&nbsp;') + '<br />'
                 
                 cherrypy.response.body = new_body
+                # Delete Content-Length header so finalize() recalcs it.
+                cherrypy.response.headers.pop("Content-Length", None)
 

cherrypy/filters/sessionauthenticatefilter.py

             error_msg = check_login_and_password(login, password)
             if error_msg:
                 cherrypy.response.body = login_screen(from_page, login = login, error_msg = error_msg)
+                # Delete Content-Length header so finalize() recalcs it.
+                cherrypy.response.headers.pop("Content-Length", None)
                 cherrypy.request.execute_main = False
             else:
                 cherrypy.session[session_key] = login
             temp_user = not_logged_in()
         if (not cherrypy.session.get(session_key)) and not temp_user:
             cherrypy.response.body = login_screen(cherrypy.request.browser_url)
+            # Delete Content-Length header so finalize() recalcs it.
+            cherrypy.response.headers.pop("Content-Length", None)
             cherrypy.request.execute_main = False
             return
         

cherrypy/filters/tidyfilter.py

                     newBody += "%03d - "%i + cgi.escape(line).replace('\t','    ').replace(' ','&nbsp;') + '<br />'
                 
                 cherrypy.response.body = newBody
+                # Delete Content-Length header so finalize() recalcs it.
+                cherrypy.response.headers.pop("Content-Length", None)
 
             elif strictXml:
                 # The HTML is OK, but is it valid XML
                     bodyFile = StringIO.StringIO()
                     traceback.print_exc(file = bodyFile)
                     cherrypy.response.body = bodyFile.getvalue()
+                    # Delete Content-Length header so finalize() recalcs it.
+                    cherrypy.response.headers.pop("Content-Length", None)
                     
                     newBody = "Wrong XML:<br />" + cgi.escape(bodyFile.getvalue().replace('\n','<br />'))
                     newBody += '<br /><br />'
                         newBody += "%03d - "%i + cgi.escape(line).replace('\t','    ').replace(' ','&nbsp;') + '<br />'
                     
                     cherrypy.response.body = newBody
+                    # Delete Content-Length header so finalize() recalcs it.
+                    cherrypy.response.headers.pop("Content-Length", None)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.