Robert Brewer committed 62bf656

Fix for #535 (Apache re-processes Range headers). _cpmodpy now uses a new "ignore_headers(['Range'])" Tool by default.

  • Participants
  • Parent commits f21580c

Comments (0)

Files changed (4)

File cherrypy/

         func = getattr(mod, fname)
-    cherrypy.config.update({'log.screen': False})
+    cherrypy.config.update({'log.screen': False,
+                            "tools.ignore_headers.on": True,
+                            "tools.ignore_headers.headers": ['Range'],
+                            })
     if cherrypy.engine.state == cherrypy._cpengine.STOPPED:

File cherrypy/

 default_toolbox.expires = Tool('before_finalize', _caching.expires)
 default_toolbox.tidy = Tool('before_finalize', tidy.tidy)
 default_toolbox.nsgmls = Tool('before_finalize', tidy.nsgmls)
+default_toolbox.ignore_headers = Tool('before_request_body', cptools.ignore_headers)
 del cptools, encoding, static, tidy

File cherrypy/lib/

             request.remote.ip = xff
+def ignore_headers(headers=('Range',)):
+    """Delete request headers whose field names are included in 'headers'.
+    This is a useful tool for working behind certain HTTP servers;
+    for example, Apache duplicates the work that CP does for 'Range'
+    headers, and will doubly-truncate the response.
+    """
+    request = cherrypy.request
+    for name in headers:
+        if name in request.headers:
+            del request.headers[name]
 def response_headers(headers=None):
     """Set headers on the response."""
     for name, value in (headers or []):

File cherrypy/test/

         import cherrypy
-            "log.error.file": os.path.join(curdir, "test.log"),
+            "log.error_file": os.path.join(curdir, "test.log"),
             "environment": "production",