summaryrefslogtreecommitdiff
path: root/wsgitools
diff options
context:
space:
mode:
Diffstat (limited to 'wsgitools')
-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)