about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2019-02-26T13·33+0100
committerVincent Ambo <mail@tazj.in>2019-02-26T13·33+0100
commitb71b44a6729f2e41a6a42543002ac7b010f26bb4 (patch)
tree6b0a2ab6a83961d81f9af167370029df934b6c77 /src/lib.rs
parent718d9457535d47c5c1f04d8d7a7bdff07ff0bad5 (diff)
fix: Correctly configure body sizes before setting read_function
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index b04f0cec3ef5..82e7322f38c8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -111,15 +111,22 @@ impl <'a> Request<'a> {
         let mut headers = HashMap::new();
         let mut body = vec![];
 
-        // Optionally set content type if a body payload is
-        // configured.
-        match self.body {
-            Body::Bytes { content_type, .. } => self.header("Content-Type", content_type),
-            Body::NoBody => Ok(&mut self),
+        // Optionally set content type if a body payload is configured
+        // and configure the expected body size.
+         match self.body {
+            Body::Bytes { content_type, data } => {
+                self.handle.post_field_size(data.len() as u64)?;
+                self.headers.append(&format!("Content-Type: {}", content_type))?;
+            },
 
             #[cfg(feature = "json")]
-            Body::Json(..) => self.header("Content-Type", "application/json"),
-        }?;
+            Body::Json(ref data) => {
+                self.handle.post_field_size(data.len() as u64)?;
+                self.headers.append("Content-Type: application/json")?;
+            },
+
+            Body::NoBody => (),
+        };
 
         // Configure headers on the request:
         self.handle.http_headers(self.headers)?;
@@ -146,7 +153,7 @@ impl <'a> Request<'a> {
                 })?,
 
                 // Do nothing if there is no body ...
-                Body::NoBody => {},
+                Body::NoBody => (),
             };
 
             // Read one header per invocation. Request processing is