Skip to content

Commit

Permalink
apply suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
zuisong committed Jun 22, 2024
1 parent 3f24597 commit 6c80a49
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use reqwest::header::{
use reqwest::Version;
use url::Url;

use crate::utils::HeaderValueExt;
use crate::{
buffer::Buffer,
cli::FormatOptions,
Expand Down Expand Up @@ -337,7 +336,7 @@ impl Printer {
header_string.push_str(key.as_str());
}
header_string.push_str(": ");
match value.to_utf8_str() {
match value.to_str() {
Ok(value) => header_string.push_str(value),
#[allow(clippy::format_push_string)]
Err(_) => header_string.push_str(&format!("{:?}", value)),
Expand Down
4 changes: 4 additions & 0 deletions src/to_curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ mod tests {
(
"xh http://example.com/[1-100].png?q={80,90}",
"curl -g 'http://example.com/[1-100].png?q={80,90}'",
),
(
"xh https://exmaple.com/ hello:你好",
"curl https://exmaple.com/ -H 'hello: 你好'"
)
];
for (input, output) in expected {
Expand Down
30 changes: 11 additions & 19 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1683,16 +1683,23 @@ fn support_utf8_header_value() {
let server = server::http(|req| async move {
assert_eq!(req.headers()["hello"].as_bytes(), "你好".as_bytes());
hyper::Response::builder()
// Valid JSON, but not declared as text
.header("hello", "你好呀")
.header("Date", "N/A")
.body("".into())
.unwrap()
});

get_command()
.args([&server.base_url(), "hello:你好"])
.assert()
.stdout(contains("Hello: 你好呀"))
.stdout(indoc! {r#"
HTTP/1.1 200 OK
Content-Length: 0
Date: N/A
Hello: "\xe4\xbd\xa0\xe5\xa5\xbd\xe5\x91\x80"
"#})
.success();
}

Expand Down Expand Up @@ -1728,7 +1735,7 @@ fn redirect_support_utf8_location() {
HTTP/1.1 302 Found
Content-Length: 14
Date: N/A
Location: /page二
Location: "/page\xe4\xba\x8c"
redirecting...
Expand All @@ -1747,21 +1754,6 @@ fn redirect_support_utf8_location() {
"#});
}

#[test]
fn to_curl_support_utf8_header_value() {
get_command()
.args(["https://exmaple.com/", "hello:你好", "--curl"])
.assert()
.stdout(contains("curl https://exmaple.com/ -H 'hello: 你好'"))
.success();

get_command()
.args(["https://exmaple.com/", "hello:你好", "--curl-long"])
.assert()
.stdout(contains("curl https://exmaple.com/ --header 'hello: 你好'"))
.success();
}

#[test]
fn mixed_stdin_request_items() {
redirecting_command()
Expand Down Expand Up @@ -3699,7 +3691,7 @@ fn multiple_format_options_are_merged() {
get_command()
.arg("--format-options=json.indent:2,json.indent:8")
.arg("--format-options=headers.sort:false")
.arg(&server.base_url())
.arg(server.base_url())
.assert()
.stdout(indoc! {r#"
HTTP/1.1 200 OK
Expand Down

0 comments on commit 6c80a49

Please sign in to comment.