Commits

Robert Brewer committed 6115503

2.x partial backport of [1406] (Fix for #588 (CherryPyWSGIServer sends Connection: close during 204 and 304 responses)).

  • Participants
  • Parent commits 262238c
  • Branches cherrypy-2.x

Comments (0)

Files changed (1)

File cherrypy/_cphttptools.py

                 del self.headers['Content-Length']
             except KeyError:
                 pass
+        elif code < 200 or code in (204, 304):
+            # "All 1xx (informational), 204 (no content),
+            # and 304 (not modified) responses MUST NOT
+            # include a message-body."
+            self.headers.pop('Content-Length', None)
+            self.body = ""
         else:
             # Responses which are not streamed should have a Content-Length,
             # but allow user code to set Content-Length if desired.
-            if (self.headers.get('Content-Length') is None
-                and code not in (304,)):
+            if self.headers.get('Content-Length') is None:
                 content = self.collapse_body()
                 self.headers['Content-Length'] = len(content)