From dec58124c70660a1a2ae8401d5c29eb01ce2cc2c Mon Sep 17 00:00:00 2001 From: zuisong Date: Fri, 21 Jun 2024 17:44:05 +0800 Subject: [PATCH] decode header value with utf-8 --- src/printer.rs | 4 ++-- src/redirect.rs | 4 ++-- src/to_curl.rs | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index 515ef950..c83776a4 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -336,8 +336,8 @@ impl Printer { header_string.push_str(key.as_str()); } header_string.push_str(": "); - match value.to_str() { - Ok(value) => header_string.push_str(value), + match String::from_utf8(value.as_bytes().to_vec()) { + Ok(value) => header_string.push_str(&value), #[allow(clippy::format_push_string)] Err(_) => header_string.push_str(&format!("{:?}", value)), } diff --git a/src/redirect.rs b/src/redirect.rs index 202fef3a..1d0ed924 100644 --- a/src/redirect.rs +++ b/src/redirect.rs @@ -51,8 +51,8 @@ fn get_next_request(mut request: Request, response: &Response) -> Option Result { if value.is_empty() { cmd.arg(format!("{};", header)); } else { - cmd.arg(format!("{}: {}", header, value.to_str()?)); + cmd.arg(format!( + "{}: {}", + header, + String::from_utf8(value.as_bytes().to_vec())? + )); } } for header in headers_to_unset {