Skip to content

Commit

Permalink
fix(common): MultiPartReader now works correctly
Browse files Browse the repository at this point in the history
The state-handling was incorrect, causing it to not handle small reads
correctly.
However, this is working nicely now.
  • Loading branch information
Byron committed Mar 18, 2015
1 parent b127df1 commit e53e23a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/rust/cmn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions src/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit e53e23a

Please sign in to comment.