summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2018-08-31 20:58:35 -0600
committerBert JW Regeer <bertjw@regeer.org>2018-08-31 20:58:35 -0600
commitfa2d2e09e08ff8f33a90ba3abc095e5604d1f696 (patch)
tree4d7c5b697e9ad95ba7eb1a5b61f2725b7a83ecaa
parent77f739a5e1ad7ffe23b34ae127447e60d4247d36 (diff)
downloadwaitress-fa2d2e09e08ff8f33a90ba3abc095e5604d1f696.tar.gz
Add new has_body property
This is used to test if a response should have a message body or not. 1xx, 204 and 304 should not have message bodies.
-rw-r--r--waitress/task.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/waitress/task.py b/waitress/task.py
index 4cfd9f8..91f4519 100644
--- a/waitress/task.py
+++ b/waitress/task.py
@@ -182,6 +182,13 @@ class Task(object):
finally:
pass
+ @property
+ def has_body(self):
+ return not (self.status.startswith('1') or
+ self.status.startswith('204') or
+ self.status.startswith('304')
+ )
+
def cancel(self):
self.close_on_finish = True
@@ -239,11 +246,12 @@ class Task(object):
if not content_length_header:
# RFC 7230: MUST NOT send Transfer-Encoding or Content-Length
- # for any response with a status code of 1xx or 204.
- if not (self.status.startswith('1') or
- self.status.startswith('204')):
+ # for any response with a status code of 1xx, 204 or 304.
+
+ if self.has_body:
response_headers.append(('Transfer-Encoding', 'chunked'))
self.chunked_response = True
+
if not self.close_on_finish:
close_on_finish()