Fixed part headers formatting and added Content-Length
This commit is contained in:
parent
fc964074d3
commit
efd784353e
|
@ -281,17 +281,21 @@ pub fn send_request(
|
||||||
|
|
||||||
for (col, val) in val.into_owned() {
|
for (col, val) in val.into_owned() {
|
||||||
if let Value::Binary { val, .. } = val {
|
if let Value::Binary { val, .. } = val {
|
||||||
let headers = format!(
|
let headers = [
|
||||||
r#"Content-Type: application/octet-stream
|
"Content-Type: application/octet-stream".to_string(),
|
||||||
Content-Disposition: form-data; name="{}"; filename="{}"
|
"Content-Transfer-Encoding: binary".to_string(),
|
||||||
Content-Transfer-Encoding: binary
|
format!(
|
||||||
"#,
|
"Content-Disposition: form-data; name=\"{}\"; filename=\"{}\"",
|
||||||
col, col,
|
col, col
|
||||||
);
|
),
|
||||||
builder.add(&mut Cursor::new(val), &headers).map_err(err)?;
|
format!("Content-Length: {}", val.len()),
|
||||||
|
];
|
||||||
|
builder
|
||||||
|
.add(&mut Cursor::new(val), &headers.join("\n"))
|
||||||
|
.map_err(err)?;
|
||||||
} else {
|
} else {
|
||||||
let headers =
|
let headers =
|
||||||
format!(r#"Content-Disposition: form-data; name="{}""#, col,);
|
format!(r#"Content-Disposition: form-data; name="{}""#, col);
|
||||||
builder
|
builder
|
||||||
.add(val.coerce_into_string()?.as_bytes(), &headers)
|
.add(val.coerce_into_string()?.as_bytes(), &headers)
|
||||||
.map_err(err)?;
|
.map_err(err)?;
|
||||||
|
|
|
@ -210,9 +210,10 @@ fn http_post_multipart_is_success() {
|
||||||
Matcher::Regex("multipart/form-data; boundary=.*".to_string()),
|
Matcher::Regex("multipart/form-data; boundary=.*".to_string()),
|
||||||
)
|
)
|
||||||
.match_body(Matcher::AllOf(vec![
|
.match_body(Matcher::AllOf(vec![
|
||||||
Matcher::Regex(r#"Content-Disposition: form-data; name="foo""#.to_string()),
|
Matcher::Regex(r#"(?m)^Content-Disposition: form-data; name="foo""#.to_string()),
|
||||||
Matcher::Regex(r#"Content-Type: application/octet-stream"#.to_string()),
|
Matcher::Regex(r#"(?m)^Content-Type: application/octet-stream"#.to_string()),
|
||||||
Matcher::Regex(r#"bar"#.to_string()),
|
Matcher::Regex(r#"(?m)^Content-Length: 3"#.to_string()),
|
||||||
|
Matcher::Regex(r#"(?m)^bar"#.to_string()),
|
||||||
]))
|
]))
|
||||||
.with_status(200)
|
.with_status(200)
|
||||||
.create();
|
.create();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user