Skip to content

Commit

Permalink
PB-932: Avoid UTF-8 truncation in logging
Browse files Browse the repository at this point in the history
The request body is in utf-8 which needs either 1 byte or 2 bytes per character
depending on the character, so we need to decode first before truncating otherwise
we might truncate in the middle of a utf-8 character and it will break the decode.
  • Loading branch information
ltshb committed Sep 12, 2024
1 parent a6bdf49 commit 67a0b8e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/middleware/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __call__(self, request):
] and request.content_type == "application/json" and not request.path.startswith(
'/api/stac/admin'
):
extra["request.payload"] = request.body[:200].decode()
extra["request.payload"] = request.body.decode()[:200]

logger.debug(
"Request %s %s?%s",
Expand Down

0 comments on commit 67a0b8e

Please sign in to comment.