From 37a8d8a135e223057dc3b2ca2c3f7425cc880c7e Mon Sep 17 00:00:00 2001 From: Jacques van Zuydam Date: Wed, 7 Jan 2026 12:18:32 +0200 Subject: [PATCH 1/2] fix(Webserver): On ASGI response, a header containing an location with a ":" would be split incorrectly, thus the redirect would fail. Splitting only first ":" character now and skipping any malformed header. --- tina4_python/__init__.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tina4_python/__init__.py b/tina4_python/__init__.py index 7ad2552..052ea40 100644 --- a/tina4_python/__init__.py +++ b/tina4_python/__init__.py @@ -413,8 +413,19 @@ async def app(scope, receive, send): if message["type"] != "websocket": response_headers = [] for header in tina4_headers: - header = header.split(":") - response_headers.append([header[0].strip().encode(), header[1].strip().encode()]) + # ensure header is a str + if isinstance(header, bytes): + header = header.decode() + else: + header = str(header) + + # split only on the first ':' to preserve ':' in values (e.g. URLs with ports) + name, sep, value = header.partition(":") + if not sep: + # malformed header, skip it + continue + + response_headers.append([name.strip().encode(), value.lstrip().encode()]) await send({ 'type': 'http.response.start', From 2149339a85953402305ae0b90f4594109cd5d595 Mon Sep 17 00:00:00 2001 From: Jacques van Zuydam Date: Wed, 7 Jan 2026 12:21:19 +0200 Subject: [PATCH 2/2] fix(Webserver): ASGI preflight response, tina4_response was None type. This caused an exception when attempting to return the preflight request. --- tina4_python/Webserver.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tina4_python/Webserver.py b/tina4_python/Webserver.py index ebb795e..bc8953a 100644 --- a/tina4_python/Webserver.py +++ b/tina4_python/Webserver.py @@ -317,7 +317,17 @@ async def get_response(self, method: str, scope ,reader: asyncio.StreamReader, w self.send_header("Access-Control-Allow-Credentials", "true", headers) headers_bytes = await self.get_headers(headers, self.response_protocol, HTTP_OK) - return headers_bytes if not asgi_response else (None, headers) + class _Tina4Response: + def __init__(self, content: str = "", http_code: int = HTTP_OK, content_type: str = "text/plain", headers: dict | None = None): + self.content = content + self.http_code = http_code + self.content_type = content_type + self.headers = headers or {} + + if not asgi_response: + return headers_bytes + + return _Tina4Response(content="", http_code=HTTP_OK, content_type="text/plain", headers={}), headers # ------------------------------------------------------------------ # Query string parsing with nested support @@ -592,4 +602,4 @@ def server_close(self): """ if self.server: self.server.close() - self.running = False \ No newline at end of file + self.running = False