Skip to content

Commit

Permalink
Minify JSON websocket data via send_json (#2128)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
  • Loading branch information
dosisod and Kludex authored Apr 28, 2023
1 parent f3cf506 commit ac469df
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion starlette/testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def send_bytes(self, data: bytes) -> None:

def send_json(self, data: typing.Any, mode: str = "text") -> None:
assert mode in ["text", "binary"]
text = json.dumps(data)
text = json.dumps(data, separators=(",", ":"))
if mode == "text":
self.send({"type": "websocket.receive", "text": text})
else:
Expand Down
2 changes: 1 addition & 1 deletion starlette/websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async def send_bytes(self, data: bytes) -> None:
async def send_json(self, data: typing.Any, mode: str = "text") -> None:
if mode not in {"text", "binary"}:
raise RuntimeError('The "mode" argument should be "text" or "binary".')
text = json.dumps(data)
text = json.dumps(data, separators=(",", ":"))
if mode == "text":
await self.send({"type": "websocket.send", "text": text})
else:
Expand Down

0 comments on commit ac469df

Please sign in to comment.