From bdc1b9a89cfd76cd95a13d2b459479d9fede2a65 Mon Sep 17 00:00:00 2001 From: Sergey Vasilyev Date: Sun, 8 Oct 2023 23:12:41 +0200 Subject: [PATCH] Ensure the reason is never an empty string, but None in HTTP responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise, `aiohttp` (in tests) cannot parse the response with the trailing space in the status — `"HTTP/1.1 555 "` — since `"555 ".split()` returns only one element, and the whole string `"555 "` is used as the status with expectations of being a 3-digit numeric. Signed-off-by: Sergey Vasilyev --- kopf/_kits/webhooks.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kopf/_kits/webhooks.py b/kopf/_kits/webhooks.py index 1f934748..0884fad0 100644 --- a/kopf/_kits/webhooks.py +++ b/kopf/_kits/webhooks.py @@ -214,13 +214,13 @@ async def _serve( response = await fn(data, webhook=webhook, sslpeer=sslpeer, headers=headers) return aiohttp.web.json_response(response) except admission.AmbiguousResourceError as e: - raise aiohttp.web.HTTPConflict(reason=str(e)) + raise aiohttp.web.HTTPConflict(reason=str(e) or None) except admission.UnknownResourceError as e: - raise aiohttp.web.HTTPNotFound(reason=str(e)) + raise aiohttp.web.HTTPNotFound(reason=str(e) or None) except admission.WebhookError as e: - raise aiohttp.web.HTTPBadRequest(reason=str(e)) + raise aiohttp.web.HTTPBadRequest(reason=str(e) or None) except json.JSONDecodeError as e: - raise aiohttp.web.HTTPBadRequest(reason=str(e)) + raise aiohttp.web.HTTPBadRequest(reason=str(e) or None) @staticmethod def _allocate_free_port() -> int: