can not combine compress with multipart

This commit is contained in:
zuisong 2025-02-04 22:46:37 +08:00
parent 53e7bbd88a
commit d9026f1850
No known key found for this signature in database
GPG Key ID: A617F31AFE6F5E8D
4 changed files with 16 additions and 4 deletions

View File

@ -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]' \

View File

@ -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.

View File

@ -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)?;

View File

@ -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...'",
));
}