fix: Correctly configure body sizes before setting read_function
This commit is contained in:
parent
718d945753
commit
b71b44a672
1 changed files with 15 additions and 8 deletions
21
src/lib.rs
21
src/lib.rs
|
@ -111,15 +111,22 @@ impl <'a> Request<'a> {
|
||||||
let mut headers = HashMap::new();
|
let mut headers = HashMap::new();
|
||||||
let mut body = vec![];
|
let mut body = vec![];
|
||||||
|
|
||||||
// Optionally set content type if a body payload is
|
// Optionally set content type if a body payload is configured
|
||||||
// configured.
|
// and configure the expected body size.
|
||||||
match self.body {
|
match self.body {
|
||||||
Body::Bytes { content_type, .. } => self.header("Content-Type", content_type),
|
Body::Bytes { content_type, data } => {
|
||||||
Body::NoBody => Ok(&mut self),
|
self.handle.post_field_size(data.len() as u64)?;
|
||||||
|
self.headers.append(&format!("Content-Type: {}", content_type))?;
|
||||||
|
},
|
||||||
|
|
||||||
#[cfg(feature = "json")]
|
#[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:
|
// Configure headers on the request:
|
||||||
self.handle.http_headers(self.headers)?;
|
self.handle.http_headers(self.headers)?;
|
||||||
|
@ -146,7 +153,7 @@ impl <'a> Request<'a> {
|
||||||
})?,
|
})?,
|
||||||
|
|
||||||
// Do nothing if there is no body ...
|
// Do nothing if there is no body ...
|
||||||
Body::NoBody => {},
|
Body::NoBody => (),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Read one header per invocation. Request processing is
|
// Read one header per invocation. Request processing is
|
||||||
|
|
Loading…
Reference in a new issue