summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-01-17 00:55:26 -0500
committerChris McDonough <chrism@plope.com>2012-01-17 00:55:26 -0500
commit5517a0b0f8464b9ac2f110375aefe9ef7b8431b8 (patch)
tree60bbc2a0972e9a6b7e25b3dc0ab31816d40e06fa
parent3d9ab4d9d895f0b760f2dcf300e176de6b355f88 (diff)
downloadwaitress-5517a0b0f8464b9ac2f110375aefe9ef7b8431b8.tar.gz
using -1 as a sentinel was a bad idea
-rw-r--r--waitress/task.py15
-rw-r--r--waitress/tests/test_task.py2
2 files changed, 7 insertions, 10 deletions
diff --git a/waitress/task.py b/waitress/task.py
index 41e9cf3..35d93fc 100644
--- a/waitress/task.py
+++ b/waitress/task.py
@@ -149,7 +149,7 @@ class Task(object):
status = '200 OK'
wrote_header = False
start_time = 0
- content_length = -1
+ content_length = None
content_bytes_written = 0
logged_write_excess = False
complete = False
@@ -210,7 +210,7 @@ class Task(object):
# replace with properly capitalized version
response_headers[i] = (headername, headerval)
- if content_length_header is None and self.content_length != -1:
+ if content_length_header is None and self.content_length is not None:
content_length_header = str(self.content_length)
self.response_headers.append(
('Content-Length', content_length_header)
@@ -291,7 +291,7 @@ class Task(object):
# use chunked encoding response
towrite = tobytes(hex(len(data))[2:].upper()) + b'\r\n'
towrite += data + b'\r\n'
- elif cl != -1:
+ elif cl is not None:
towrite = data[:cl-self.content_bytes_written]
self.content_bytes_written += len(towrite)
if towrite != data and not self.logged_write_excess:
@@ -382,8 +382,6 @@ class WSGITask(Task):
try:
if app_iter.__class__ is ReadOnlyFileBasedBuffer:
cl = self.content_length
- if cl == -1:
- cl = None
size = app_iter.prepare(cl)
if size:
if cl != size:
@@ -393,8 +391,7 @@ class WSGITask(Task):
self.write(b'') # generate headers
self.channel.write_soon(app_iter)
return
- # By iterating manually at this point, we execute task.write()
- # multiple times, allowing partial data to be sent.
+
first_chunk_len = None
for chunk in app_iter:
if first_chunk_len is None:
@@ -403,7 +400,7 @@ class WSGITask(Task):
# start_response may not have been called until first
# iteration as per PEP, so we must reinterrogate
# self.content_length here
- if self.content_length == -1:
+ if self.content_length is None:
app_iter_len = None
if hasattr(app_iter, '__len__'):
app_iter_len = len(app_iter)
@@ -415,7 +412,7 @@ class WSGITask(Task):
self.write(chunk)
cl = self.content_length
- if cl != -1:
+ if cl is not None:
if self.content_bytes_written != cl:
# close the connection so the client isn't sitting around
# waiting for more data when there are too few bytes
diff --git a/waitress/tests/test_task.py b/waitress/tests/test_task.py
index 041bab6..1493b21 100644
--- a/waitress/tests/test_task.py
+++ b/waitress/tests/test_task.py
@@ -433,7 +433,7 @@ class TestWSGITask(unittest.TestCase):
inst = self._makeOne()
inst.channel.server.application = app
inst.execute()
- self.assertEqual(inst.content_length, -1)
+ self.assertEqual(inst.content_length, None)
def test_execute_app_returns_too_many_bytes(self):
def app(environ, start_response):