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.
This commit is contained in:
Sebastian Thiel
2015-03-18 21:02:08 +01:00
parent b127df17b0
commit e53e23a893
2 changed files with 5 additions and 5 deletions

View File

@@ -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)
}

View File

@@ -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);
}
}