Skip to content

Commit

Permalink
fix StreamingResponse message content encoding (#55)
Browse files Browse the repository at this point in the history
* encode message_str

* 🎨 lint code

* 💚 fix CI

---------

Co-authored-by: Ajinkya Indulkar <26824103+ajndkr@users.noreply.github.com>
  • Loading branch information
rbbby and ajndkr authored May 22, 2023
1 parent 45d16dc commit e64d180
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:
env:
PYTHON_VERSION: 3.9
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build-and-test:
Expand Down
8 changes: 6 additions & 2 deletions lanarky/callbacks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ class AsyncStreamingResponseCallback(AsyncLanarkyCallback):

def _construct_message(self, message_str: str) -> Message:
"""Construct a Message from a string."""
return {"type": "http.response.body", "body": message_str, "more_body": True}
return {
"type": "http.response.body",
"body": message_str.encode("utf-8"),
"more_body": True,
}


class AsyncWebsocketCallback(AsyncLanarkyCallback):
Expand All @@ -44,4 +48,4 @@ class AsyncWebsocketCallback(AsyncLanarkyCallback):

def _construct_message(self, message_str: str) -> dict:
"""Construct a WebsocketResponse from a string."""
return {**self.response.dict(), **{"message": message_str}}
return {**self.response.dict(), **{"message": message_str.encode("utf-8")}}

0 comments on commit e64d180

Please sign in to comment.