Ensure no HTTP body is sent when not specified

When calling the `http::put()`, `http::post()`, and `http::patch()` SQL functions, the HTTP body is not added or sent if it is specified as `NONE`.

Closes #1492
This commit is contained in:
Tobie Morgan Hitchcock 2022-11-27 10:13:29 +00:00
parent 37871ceb81
commit f0520313b5

View file

@ -78,7 +78,9 @@ pub async fn put(uri: Strand, body: Value, opts: impl Into<Object>) -> Result<Va
req = req.header(k.as_str(), v.to_strand().as_str());
}
// Submit the request body
req = req.body_json(&body)?;
if body.is_some() {
req = req.body_json(&body)?;
}
// Send the request and wait
let mut res = req.send().await?;
// Check the response status
@ -112,7 +114,9 @@ pub async fn post(uri: Strand, body: Value, opts: impl Into<Object>) -> Result<V
req = req.header(k.as_str(), v.to_strand().as_str());
}
// Submit the request body
req = req.body_json(&body)?;
if body.is_some() {
req = req.body_json(&body)?;
}
// Send the request and wait
let mut res = req.send().await?;
// Check the response status
@ -146,7 +150,9 @@ pub async fn patch(uri: Strand, body: Value, opts: impl Into<Object>) -> Result<
req = req.header(k.as_str(), v.to_strand().as_str());
}
// Submit the request body
req = req.body_json(&body)?;
if body.is_some() {
req = req.body_json(&body)?;
}
// Send the request and wait
let mut res = req.send().await?;
// Check the response status