From c96e5b6667b71174e7b5756aea726308176d3985 Mon Sep 17 00:00:00 2001 From: Unrud Date: Wed, 19 Jan 2022 19:58:05 +0100 Subject: [PATCH] Drop body for HEAD requests last --- radicale/app/__init__.py | 5 +++-- radicale/app/head.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/radicale/app/__init__.py b/radicale/app/__init__.py index aab4beb..8ffda13 100644 --- a/radicale/app/__init__.py +++ b/radicale/app/__init__.py @@ -117,6 +117,8 @@ class Application(ApplicationPartDelete, ApplicationPartHead, headers = [*raw_headers, ("Content-Length", str(len(answer)))] answers = [answer] start_response(status_text, headers) + if environ.get("REQUEST_METHOD") == "HEAD": + return [] return answers def _handle_request(self, environ: types.WSGIEnviron @@ -148,8 +150,7 @@ class Application(ApplicationPartDelete, ApplicationPartHead, headers["Content-Encoding"] = "gzip" headers["Content-Length"] = str(len(answer)) - if request_method != "HEAD": - answers.append(answer) + answers.append(answer) # Add extra headers set in configuration headers.update(self._extra_headers) diff --git a/radicale/app/head.py b/radicale/app/head.py index b6178f6..5166db2 100644 --- a/radicale/app/head.py +++ b/radicale/app/head.py @@ -27,5 +27,5 @@ class ApplicationPartHead(ApplicationPartGet, ApplicationBase): def do_HEAD(self, environ: types.WSGIEnviron, base_prefix: str, path: str, user: str) -> types.WSGIResponse: """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)