Skip to content

Commit

Permalink
decode header value with utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
zuisong committed Jun 21, 2024
1 parent d8e80be commit dec5812
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
Expand Down
4 changes: 2 additions & 2 deletions src/redirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ fn get_next_request(mut request: Request, response: &Response) -> Option<Request
response
.headers()
.get(LOCATION)
.and_then(|location| location.to_str().ok())
.and_then(|location| request.url().join(location).ok())
.and_then(|location| String::from_utf8(location.as_bytes().to_vec()).ok())
.and_then(|location| request.url().join(&location).ok())
};

match response.status() {
Expand Down
6 changes: 5 additions & 1 deletion src/to_curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,11 @@ pub fn translate(args: Cli) -> Result<Command> {
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 {
Expand Down

0 comments on commit dec5812

Please sign in to comment.