Skip to content

Commit

Permalink
Avoid closing connections when HEAD requests have a content length
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Dec 21, 2023
1 parent 84360df commit 20ea011
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/waitress/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,17 +474,18 @@ def start_response(status, headers, exc_info=None):

cl = self.content_length
if cl is not None:
if self.content_bytes_written != cl:
if self.content_bytes_written != cl and self.request.command != "HEAD":
# close the connection so the client isn't sitting around
# waiting for more data when there are too few bytes
# to service content-length
# unless it's a HEAD request in which case we don't expect
# to return any bytes regardless of the content length
self.close_on_finish = True
if self.request.command != "HEAD":
self.logger.warning(
"application returned too few bytes (%s) "
"for specified Content-Length (%s) via app_iter"
% (self.content_bytes_written, cl),
)
self.logger.warning(
"application returned too few bytes (%s) "
"for specified Content-Length (%s) via app_iter"
% (self.content_bytes_written, cl),
)
finally:
if can_close_app_iter and hasattr(app_iter, "close"):
app_iter.close()
Expand Down

0 comments on commit 20ea011

Please # to comment.