Skip to content

Commit

Permalink
Ensure response to HEAD request won't have message body
Browse files Browse the repository at this point in the history
Ensure that Gunicorn won't try to use chunked transfer-encoding for responses
to a HEAD request, so that `Response.close` will not write a terminating
chunk. Responses to a HEAD request MUST NOT have a message-body.

The application is still responsible for ensuring no message body is actually
generated in response to a HEAD request.
  • Loading branch information
darkrain42 committed Jan 4, 2016
1 parent aed133f commit 8926565
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gunicorn/http/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ def should_close(self):
return True
if self.response_length is not None or self.chunked:
return False
if self.req.method == 'HEAD':
return False
if self.status_code < 200 or self.status_code in (204, 304):
return False
return True
Expand Down Expand Up @@ -287,6 +289,9 @@ def is_chunked(self):
return False
elif self.req.version <= (1, 0):
return False
elif self.req.method == 'HEAD':
# Responses to a HEAD request MUST NOT contain a response body.
return False
elif self.status_code in (204, 304):
# Do not use chunked responses when the response is guaranteed to
# not have a response body.
Expand Down

0 comments on commit 8926565

Please sign in to comment.