From 78870186d70e05bf347c7ee3ddc245391cafe9bc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 10 Nov 2023 07:31:01 -0600 Subject: [PATCH] Use content-type fast path for common case (#4685) This is a port of https://github.com/home-assistant/core/pull/103477 from core --- supervisor/api/ingress.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/supervisor/api/ingress.py b/supervisor/api/ingress.py index 7865ca7bf..3672db5de 100644 --- a/supervisor/api/ingress.py +++ b/supervisor/api/ingress.py @@ -225,7 +225,11 @@ class APIIngress(CoreSysAttributes): skip_auto_headers={hdrs.CONTENT_TYPE}, ) as result: headers = _response_header(result) - + # Avoid parsing content_type in simple cases for better performance + if maybe_content_type := result.headers.get(hdrs.CONTENT_TYPE): + content_type = (maybe_content_type.partition(";"))[0].strip() + else: + content_type = result.content_type # Simple request if ( hdrs.CONTENT_LENGTH in result.headers @@ -236,13 +240,13 @@ class APIIngress(CoreSysAttributes): return web.Response( headers=headers, status=result.status, - content_type=result.content_type, + content_type=content_type, body=body, ) # Stream response response = web.StreamResponse(status=result.status, headers=headers) - response.content_type = result.content_type + response.content_type = content_type try: await response.prepare(request)