Skip to content

Commit

Permalink
Continue decompressing chunks even after hyper is done downloading th…
Browse files Browse the repository at this point in the history
…e body

If hyper reads compressed enough data, we were decompressing 32k by 32k
but we were throwing away the end of the body because we would end up
having lots of backed up data in the cursor when hyper was done.
  • Loading branch information
Eijebong committed Nov 8, 2018
1 parent e30440c commit dcbe7d3
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion components/net/connector.rs
Expand Up @@ -110,7 +110,37 @@ impl Stream for WrappedBody {
},
}
} else {
None
// Hyper is done downloading but we still have uncompressed data
match self.decoder {
Decoder::Gzip(Some(ref mut decoder)) => {
let mut buf = vec![0; BUF_SIZE];
let len = decoder.read(&mut buf).ok()?;
if len == 0 {
return None;
}
buf.truncate(len);
Some(buf.into())
},
Decoder::Deflate(ref mut decoder) => {
let mut buf = vec![0; BUF_SIZE];
let len = decoder.read(&mut buf).ok()?;
if len == 0 {
return None;
}
buf.truncate(len);
Some(buf.into())
},
Decoder::Brotli(ref mut decoder) => {
let mut buf = vec![0; BUF_SIZE];
let len = decoder.read(&mut buf).ok()?;
if len == 0 {
return None;
}
buf.truncate(len);
Some(buf.into())
},
_ => None,
}
}
})
})
Expand Down

0 comments on commit dcbe7d3

Please sign in to comment.