From 0e45887873701e054db6d189de9abc49b9aa0db7 Mon Sep 17 00:00:00 2001 From: BoryaGames <67229357+BoryaGames@users.noreply.github.com> Date: Mon, 21 Oct 2024 22:02:14 +0500 Subject: [PATCH] Fix bytes --- cattopy/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cattopy/main.py b/cattopy/main.py index af24fe8..15d2333 100644 --- a/cattopy/main.py +++ b/cattopy/main.py @@ -95,7 +95,7 @@ async def _handler( } ) await send( - {"type": "http.response.body", "body": result.content.encode()} + {"type": "http.response.body", "body": result.content} ) elif result == Skip: continue @@ -258,25 +258,25 @@ def __init__( self.request = request self.status = status self.headers = headers - self.content = "" + self.content = b"" def text(self, content: str): - self.content = content + self.content = content.encode() self.headers["content-type"] = "text/plain" return self def json(self, content: dict[Any, Any]): - self.content = json.dumps(content, indent=2) + self.content = json.dumps(content, indent=2).encode() self.headers["content-type"] = "application/json" return self def html(self, content: str): - self.content = content + self.content = content.encode() self.headers["content-type"] = "text/html" return self def file(self, path: str): - with open(path, "r") as file: + with open(path, "rb") as file: self.content = file.read() self.headers["content-type"] = mimetypes.guess_type(path)[0] or "text/plain" return self