summaryrefslogtreecommitdiff
path: root/wsgitools/middlewares.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2019-01-17 20:57:53 +0100
committerHelmut Grohne <helmut@subdivi.de>2019-01-17 20:57:53 +0100
commit148190c2473f95d583568fa21c336e29c63633ec (patch)
tree8b03acab4c4d2b2b3fc19c0fbb0866c46658fa8d /wsgitools/middlewares.py
parentbbdc0eb818eb26d5da0ec2ae6cf724332550e9a9 (diff)
downloadwsgitools-148190c2473f95d583568fa21c336e29c63633ec.tar.gz
ContentLengthMiddleware: don't duplicate the header
When an iterable is returned and a Content-Length header is already present, don't add a second one.
Diffstat (limited to 'wsgitools/middlewares.py')
-rw-r--r--wsgitools/middlewares.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/wsgitools/middlewares.py b/wsgitools/middlewares.py
index 97b8092..1619e0b 100644
--- a/wsgitools/middlewares.py
+++ b/wsgitools/middlewares.py
@@ -166,7 +166,7 @@ class ContentLengthMiddleware(object):
gotdata = True
assert bool(todo)
status, headers = todo[0]
- if not [k for k, _ in headers if k.lower() == "content-length"]:
+ if all(k.lower() != "content-length" for k, _ in headers):
length = sum(map(len, ret))
headers.append(("Content-Length", str(length)))
start_response(status, headers)
@@ -188,17 +188,18 @@ class ContentLengthMiddleware(object):
data.append(first)
length = len(first)
- while (not stopped) and length < self.maxstore:
- try:
- data.append(next(ret))
- length += len(data[-1])
- except StopIteration:
- stopped = True
+ if all(k.lower() != "content-length" for k, _ in headers):
+ while (not stopped) and length < self.maxstore:
+ try:
+ data.append(next(ret))
+ length += len(data[-1])
+ except StopIteration:
+ stopped = True
- if stopped:
- headers.append(("Content-length", str(length)))
- start_response(status, headers)
- return data
+ if stopped:
+ headers.append(("Content-length", str(length)))
+ start_response(status, headers)
+ return data
start_response(status, headers)