Skip to content

Commit

Permalink
Ensure the reason is never an empty string, but None in HTTP responses
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nolar committed Oct 8, 2023
1 parent 538df59 commit bdc1b9a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions kopf/_kits/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bdc1b9a

Please sign in to comment.