summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cherrypy/_cpmodpy.py5
-rw-r--r--cherrypy/_cptools.py1
-rw-r--r--cherrypy/lib/cptools.py13
-rw-r--r--cherrypy/test/modpy.py2
4 files changed, 19 insertions, 2 deletions
diff --git a/cherrypy/_cpmodpy.py b/cherrypy/_cpmodpy.py
index 1573ade9..03f5573a 100644
--- a/cherrypy/_cpmodpy.py
+++ b/cherrypy/_cpmodpy.py
@@ -18,7 +18,10 @@ def setup(req):
func = getattr(mod, fname)
func()
- 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:
cherrypy.engine.start(blocking=False)
diff --git a/cherrypy/_cptools.py b/cherrypy/_cptools.py
index ee007ecb..90135c24 100644
--- a/cherrypy/_cptools.py
+++ b/cherrypy/_cptools.py
@@ -312,6 +312,7 @@ default_toolbox.caching = CachingTool()
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
diff --git a/cherrypy/lib/cptools.py b/cherrypy/lib/cptools.py
index 43c010c7..f3f374ea 100644
--- a/cherrypy/lib/cptools.py
+++ b/cherrypy/lib/cptools.py
@@ -122,6 +122,19 @@ def proxy(base=None, local='X-Forwarded-Host', remote='X-Forwarded-For'):
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 []):
diff --git a/cherrypy/test/modpy.py b/cherrypy/test/modpy.py
index 269e8cca..26a854c9 100644
--- a/cherrypy/test/modpy.py
+++ b/cherrypy/test/modpy.py
@@ -110,7 +110,7 @@ def wsgisetup(req):
import cherrypy
cherrypy.config.update({
- "log.error.file": os.path.join(curdir, "test.log"),
+ "log.error_file": os.path.join(curdir, "test.log"),
"environment": "production",
})
cherrypy.engine.start(blocking=False)