fix(net/crimp): correctly set content length for PUT requests
Since https://github.com/curl/curl/commit/9c845be2797e20475 (presumably), libcurl will overwrite our previously set request method to POST if we set .post_field_size(…). The fix is to use the proper option for PUT/upload, .in_filesize(…). While we're at it, switch to using .upload(…) instead of the deprecated .put(…) which should be the same for HTTP. Change-Id: I393c1a02c70d5b99dff5901cd6e9d9434f68c15b Reviewed-on: https://cl.tvl.fyi/c/depot/+/11132 Tested-by: BuildkiteCI Autosubmit: sterni <sternenseemann@systemli.org> Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
54609e8c17
commit
438db1be30
1 changed files with 12 additions and 3 deletions
|
@ -365,7 +365,7 @@ impl<'a> Request<'a> {
|
||||||
match self.method {
|
match self.method {
|
||||||
Method::Get => self.handle.get(true)?,
|
Method::Get => self.handle.get(true)?,
|
||||||
Method::Post => self.handle.post(true)?,
|
Method::Post => self.handle.post(true)?,
|
||||||
Method::Put => self.handle.put(true)?,
|
Method::Put => self.handle.upload(true)?,
|
||||||
Method::Patch => self.handle.custom_request("PATCH")?,
|
Method::Patch => self.handle.custom_request("PATCH")?,
|
||||||
Method::Delete => self.handle.custom_request("DELETE")?,
|
Method::Delete => self.handle.custom_request("DELETE")?,
|
||||||
}
|
}
|
||||||
|
@ -386,14 +386,23 @@ impl<'a> Request<'a> {
|
||||||
// and configure the expected body size (or form payload).
|
// and configure the expected body size (or form payload).
|
||||||
match self.body {
|
match self.body {
|
||||||
Body::Bytes { content_type, data } => {
|
Body::Bytes { content_type, data } => {
|
||||||
self.handle.post_field_size(data.len() as u64)?;
|
match self.method {
|
||||||
|
Method::Put => self.handle.in_filesize(data.len() as u64)?,
|
||||||
|
// TODO(sterni): this may still be wrong for some request types?
|
||||||
|
_ => self.handle.post_field_size(data.len() as u64)?,
|
||||||
|
};
|
||||||
|
|
||||||
self.headers
|
self.headers
|
||||||
.append(&format!("Content-Type: {}", content_type))?;
|
.append(&format!("Content-Type: {}", content_type))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "json")]
|
#[cfg(feature = "json")]
|
||||||
Body::Json(ref data) => {
|
Body::Json(ref data) => {
|
||||||
self.handle.post_field_size(data.len() as u64)?;
|
match self.method {
|
||||||
|
Method::Put => self.handle.in_filesize(data.len() as u64)?,
|
||||||
|
// TODO(sterni): this may still be wrong for some request types?
|
||||||
|
_ => self.handle.post_field_size(data.len() as u64)?,
|
||||||
|
};
|
||||||
self.headers.append("Content-Type: application/json")?;
|
self.headers.append("Content-Type: application/json")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue