Avoid duplicating post headers (#5200)

* Avoid duplicating post headers

This should fix #5194

* Update post.rs

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
Dan Swain 2022-04-15 07:02:22 -04:00 committed by GitHub
parent 6a1378c1bb
commit 8e2847431e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -205,6 +205,13 @@ fn helper(
}; };
let mut request = http_client(args.insecure.is_some()).post(location); let mut request = http_client(args.insecure.is_some()).post(location);
// set the content-type header before using e.g., request.json
// because that will avoid duplicating the header value
if let Some(val) = args.content_type {
request = request.header("Content-Type", val);
}
match body { match body {
Value::Binary { val, .. } => { Value::Binary { val, .. } => {
request = request.body(val); request = request.body(val);
@ -235,9 +242,6 @@ fn helper(
} }
}; };
if let Some(val) = args.content_type {
request = request.header("Content-Type", val);
}
if let Some(val) = args.content_length { if let Some(val) = args.content_length {
request = request.header("Content-Length", val); request = request.header("Content-Length", val);
} }