diff --git a/completions/_xh b/completions/_xh index 50c83257..2f1edfd0 100644 --- a/completions/_xh +++ b/completions/_xh @@ -54,7 +54,7 @@ none\:"Disable both coloring and formatting"))' \ '--json[(default) Serialize data items from the command line as a JSON object]' \ '-f[Serialize data items from the command line as form fields]' \ '--form[Serialize data items from the command line as form fields]' \ -'(--raw)--multipart[Like --form, but force a multipart/form-data request even without files]' \ +'(--raw -x --compress)--multipart[Like --form, but force a multipart/form-data request even without files]' \ '-h[Print only the response headers. Shortcut for --print=h]' \ '--headers[Print only the response headers. Shortcut for --print=h]' \ '-b[Print only the response body. Shortcut for --print=b]' \ diff --git a/src/cli.rs b/src/cli.rs index deb5f335..54b456d1 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -60,7 +60,7 @@ pub struct Cli { /// Like --form, but force a multipart/form-data request even without files. /// /// Overrides both --json and --form. - #[clap(long, conflicts_with = "raw", overrides_with_all = &["json", "form"])] + #[clap(long, conflicts_with_all = &["raw", "compress"], overrides_with_all = &["json", "form"])] pub multipart: bool, /// Pass raw request data without extra processing. diff --git a/src/main.rs b/src/main.rs index 5ad9fd31..91b8acf5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -512,7 +512,7 @@ fn run(args: Cli) -> Result { if args.compress >= 1 && request.headers().get(CONTENT_ENCODING).is_none() { if let Some(body) = request.body_mut() { - // TODO: Compress file body (Multipart and File) without buffering + // TODO: Compress file body (File) without buffering let body_bytes = body.buffer()?; let mut encoder = ZlibEncoder::new(Vec::new(), Default::default()); encoder.write_all(body_bytes)?; diff --git a/tests/cases/compress_request_body.rs b/tests/cases/compress_request_body.rs index 848aa7d8..b5b5c089 100644 --- a/tests/cases/compress_request_body.rs +++ b/tests/cases/compress_request_body.rs @@ -87,6 +87,7 @@ fn compress_request_body_form() { key={c} "#, c = "1".repeat(1000),}); } + #[test] fn skip_compression_when_compression_ratio_is_negative() { let server = server(); @@ -105,7 +106,7 @@ fn skip_compression_when_compression_ratio_is_negative() { } #[test] -fn compress_request_body_force() { +fn test_compress_force_with_negative_ratio() { let server = server(); get_command() .arg(format!("{}/deflate", server.base_url())) @@ -195,3 +196,14 @@ fn compress_body_from_file_unless_compress_rate_less_1() { .assert() .success(); } +#[test] +fn test_cannot_combine_compress_with_multipart() { + get_command() + .arg(format!("{}/deflate", "")) + .args(["--multipart", "-x", "a=1"]) + .assert() + .failure() + .stderr(predicates::str::contains( + "the argument '--multipart' cannot be used with '--compress...'", + )); +}