about summary refs log tree commit diff
path: root/net/crimp/src/lib.rs
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2024-03-11T16·17+0100
committerclbot <clbot@tvl.fyi>2024-03-11T16·36+0000
commit438db1be3065b451ebb232e8b3308e69a9e28fa4 (patch)
treead7843d38ab9e2195c163603bf4df2fb422598f3 /net/crimp/src/lib.rs
parent54609e8c17e60c1a3feaea5430887a6cc6bdce0f (diff)
fix(net/crimp): correctly set content length for PUT requests r/7680
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>
Diffstat (limited to 'net/crimp/src/lib.rs')
-rw-r--r--net/crimp/src/lib.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/net/crimp/src/lib.rs b/net/crimp/src/lib.rs
index 4dd4d6c31bd7..7dfd261ee090 100644
--- a/net/crimp/src/lib.rs
+++ b/net/crimp/src/lib.rs
@@ -365,7 +365,7 @@ impl<'a> Request<'a> {
         match self.method {
             Method::Get => self.handle.get(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::Delete => self.handle.custom_request("DELETE")?,
         }
@@ -386,14 +386,23 @@ impl<'a> Request<'a> {
         // and configure the expected body size (or form payload).
         match self.body {
             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
                     .append(&format!("Content-Type: {}", content_type))?;
             }
 
             #[cfg(feature = "json")]
             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")?;
             }