Allow bytes content HTTPRepsonse

This commit is contained in:
0880
2026-01-17 18:31:27 +03:30
parent 014cdd80e2
commit 4e04784f9b

View File

@@ -260,12 +260,14 @@ class App:
def HTTPResponse(
request: Request,
content: str,
content: str | bytes,
status=200,
content_type="text/plain; charset=utf-8",
headers=[],
) -> bytes:
content_bytes = content.encode(encoding="utf-8")
content_bytes = content
if isinstance(content, str):
content_bytes = content.encode(encoding="utf-8")
head: str = f"HTTP/1.1 {status} {http.client.responses.get(status, 'Unkown Status Code')}\r\nContent-Type: {content_type}\r\nContent-Length: {len(content_bytes)}\r\n"
if (
"origin" in request.headers