Drop body for HEAD requests last

This commit is contained in:
Unrud 2022-01-19 19:58:05 +01:00
parent 4822807c4d
commit c96e5b6667
2 changed files with 4 additions and 3 deletions

View File

@ -117,6 +117,8 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
headers = [*raw_headers, ("Content-Length", str(len(answer)))] headers = [*raw_headers, ("Content-Length", str(len(answer)))]
answers = [answer] answers = [answer]
start_response(status_text, headers) start_response(status_text, headers)
if environ.get("REQUEST_METHOD") == "HEAD":
return []
return answers return answers
def _handle_request(self, environ: types.WSGIEnviron def _handle_request(self, environ: types.WSGIEnviron
@ -148,7 +150,6 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
headers["Content-Encoding"] = "gzip" headers["Content-Encoding"] = "gzip"
headers["Content-Length"] = str(len(answer)) headers["Content-Length"] = str(len(answer))
if request_method != "HEAD":
answers.append(answer) answers.append(answer)
# Add extra headers set in configuration # Add extra headers set in configuration

View File

@ -27,5 +27,5 @@ class ApplicationPartHead(ApplicationPartGet, ApplicationBase):
def do_HEAD(self, environ: types.WSGIEnviron, base_prefix: str, path: str, def do_HEAD(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
user: str) -> types.WSGIResponse: user: str) -> types.WSGIResponse:
"""Manage HEAD request.""" """Manage HEAD request."""
# Body is dropped in `Application._handle_request` for HEAD requests # Body is dropped in `Application.__call__` for HEAD requests
return self.do_GET(environ, base_prefix, path, user) return self.do_GET(environ, base_prefix, path, user)