Skip to content

Commit

Permalink
Fix bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
BoryaGames authored Oct 21, 2024
1 parent 27b0744 commit 0e45887
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cattopy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0e45887

Please sign in to comment.