summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2018-12-27 17:58:29 +0100
committerHelmut Grohne <helmut@subdivi.de>2018-12-27 17:58:29 +0100
commitbbdc0eb818eb26d5da0ec2ae6cf724332550e9a9 (patch)
tree2f93bc5faf8bea3a0f540d256941a5071950c7d6
parent7f1c15ee300a1212a27616c194fe0f293d2b7598 (diff)
downloadwsgitools-bbdc0eb818eb26d5da0ec2ae6cf724332550e9a9.tar.gz
fix ContentLengthMiddleware(..., maxstore=()) on Py3k
On Python 2.x, any integer sorts below the empty tuple. That was exploited in the maxstore parameter, but fails on Python 3 with a TypeError. Also add a regression test. Reported-by: Dominik Brodowski <mail@dominikbrodowski.net>
-rwxr-xr-xtest.py12
-rw-r--r--wsgitools/middlewares.py2
2 files changed, 12 insertions, 2 deletions
diff --git a/test.py b/test.py
index 6aef5bf..bbb11b9 100755
--- a/test.py
+++ b/test.py
@@ -276,14 +276,15 @@ class StupidIO(object):
return self.content[oldpos:self.position]
class ContentLengthMiddlewareTest(unittest.TestCase):
- def setUp(self):
+ def customSetUp(self, maxstore=10):
self.staticapp = applications.StaticFile(StupidIO(b"success"),
"200 Found", [("Content-Type", "text/plain")])
self.app = middlewares.ContentLengthMiddleware(self.staticapp,
- maxstore=10)
+ maxstore=maxstore)
self.req = Request(self)
def testWithout(self):
+ self.customSetUp()
res = self.req(self.staticapp)
res.status("200 Found")
try:
@@ -293,6 +294,13 @@ class ContentLengthMiddlewareTest(unittest.TestCase):
pass
def testGet(self):
+ self.customSetUp()
+ res = self.req(self.app)
+ res.status("200 Found")
+ res.header("Content-length", "7")
+
+ def testInfiniteMaxstore(self):
+ self.customSetUp(maxstore=())
res = self.req(self.app)
res.status("200 Found")
res.header("Content-length", "7")
diff --git a/wsgitools/middlewares.py b/wsgitools/middlewares.py
index b37b130..97b8092 100644
--- a/wsgitools/middlewares.py
+++ b/wsgitools/middlewares.py
@@ -137,6 +137,8 @@ class ContentLengthMiddleware(object):
wsgi standard
"""
self.app = app
+ if maxstore == ():
+ maxstore = float("inf")
self.maxstore = maxstore
def __call__(self, environ, start_response):
"""wsgi interface"""