Skip to content

Commit

Permalink
Avoid calling decode() and allocating strings for logging if said l…
Browse files Browse the repository at this point in the history
…og lines will no-op anyways.
  • Loading branch information
James Udiljak committed Apr 3, 2024
1 parent 54d6442 commit 6ba3b86
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sse_starlette/sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async def stream_response(self, send: Send) -> None:
)
async for data in self.body_iterator:
chunk = ensure_bytes(data, self.sep)
_log.debug(f"chunk: {chunk.decode()}")
if _log.isEnabledFor(logging.DEBUG): _log.debug(f"chunk: {chunk.decode()}")
with anyio.move_on_after(self.send_timeout) as timeout:
await send(
{"type": "http.response.body", "body": chunk, "more_body": True}
Expand Down Expand Up @@ -322,7 +322,7 @@ async def _ping(self, send: Send) -> None:
if self.ping_message_factory is None
else ensure_bytes(self.ping_message_factory(), self.sep)
)
_log.debug(f"ping: {ping.decode()}")
if _log.isEnabledFor(logging.DEBUG): _log.debug(f"ping: {ping.decode()}")
async with self._send_lock:
if self.active:
await send(
Expand Down

0 comments on commit 6ba3b86

Please sign in to comment.