Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
bugfix: fix a crash problem due to incorrect utf8 slicing (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninegua authored Jan 31, 2022
1 parent 4b0edcf commit b0de043
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,13 @@ async fn forward_request(

slog::trace!(logger, "<<");
if logger.is_trace_enabled() {
let body = String::from_utf8_lossy(&entire_body);
let body = String::from_utf8_lossy(
&entire_body[0..usize::min(entire_body.len(), MAX_LOG_BODY_SIZE)],
);
slog::trace!(
logger,
"<< {}{}",
&body[0..usize::min(body.len(), MAX_LOG_BODY_SIZE)],
"<< \"{}\"{}",
&body.escape_default(),
if body.len() > MAX_LOG_BODY_SIZE {
format!("... {} bytes total", body.len())
} else {
Expand Down Expand Up @@ -449,14 +451,9 @@ async fn forward_request(
slog::trace!(logger, ">>");
slog::trace!(
logger,
">> {}{}",
match std::str::from_utf8(&body) {
Ok(s) => format!(
r#""{}""#,
s[..usize::min(MAX_LOG_BODY_SIZE, s.len())].escape_default()
),
Err(_) => hex::encode(&body[..usize::min(MAX_LOG_BODY_SIZE, body.len())]),
},
">> \"{}\"{}",
String::from_utf8_lossy(&body[..usize::min(MAX_LOG_BODY_SIZE, body.len())])
.escape_default(),
if is_streaming {
"... streaming".to_string()
} else if body.len() > MAX_LOG_BODY_SIZE {
Expand Down

0 comments on commit b0de043

Please sign in to comment.