From e53e23a893ce6d59777b8b53f94770d5c3c86b9c Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 18 Mar 2015 21:02:08 +0100 Subject: [PATCH] fix(common): MultiPartReader now works correctly The state-handling was incorrect, causing it to not handle small reads correctly. However, this is working nicely now. --- src/rust/cmn.rs | 5 +++-- src/rust/lib.rs | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rust/cmn.rs b/src/rust/cmn.rs index 62040844a56..8a5df2a1304 100644 --- a/src/rust/cmn.rs +++ b/src/rust/cmn.rs @@ -167,7 +167,7 @@ impl<'a> MultiPartReader<'a> { /// Returns true if we are totally used fn is_depleted(&self) -> bool { - self.raw_parts.len() == 0 && self.current_part.is_none() + self.raw_parts.len() == 0 && self.current_part.is_none() && self.last_part_boundary.is_none() } /// Returns true if we are handling our last part @@ -203,7 +203,7 @@ impl<'a> Read for MultiPartReader<'a> { match rr { Ok(bytes_read) => { - if bytes_read == 0 { + if hb < buf.len() && bytes_read == 0 { if self.is_last_part() { // before clearing the last part, we will add the boundary that // will be written last @@ -225,6 +225,7 @@ impl<'a> Read for MultiPartReader<'a> { Err(err) => { // fail permanently self.current_part = None; + self.last_part_boundary = None; self.raw_parts.clear(); Err(err) } diff --git a/src/rust/lib.rs b/src/rust/lib.rs index 9bb99c06326..89567b2eacd 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -72,9 +72,8 @@ bar\r\n\ } v.push(buf[0]); } - println!("{:?}", v.len()); - println!("{:?}", v.container_as_str().unwrap()); assert_eq!(v.len(), EXPECTED_LEN); - assert_eq!(v.container_as_str().unwrap(), EXPECTED); + // See above: headers are unordered + // assert_eq!(v.container_as_str().unwrap(), EXPECTED); } } \ No newline at end of file