Skip to content

Commit

Permalink
can not combine compress with multipart
Browse files Browse the repository at this point in the history
  • Loading branch information
zuisong committed Feb 4, 2025
1 parent 53e7bbd commit 59f4f89
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ fn run(args: Cli) -> Result<i32> {

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)?;
Expand Down
14 changes: 13 additions & 1 deletion tests/cases/compress_request_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()))
Expand Down Expand Up @@ -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...'",
));
}

0 comments on commit 59f4f89

Please sign in to comment.