summaryrefslogtreecommitdiff
path: root/src/http_body.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/http_body.rs')
-rw-r--r--src/http_body.rs47
1 files changed, 22 insertions, 25 deletions
diff --git a/src/http_body.rs b/src/http_body.rs
index 4931ee4bd..e75e3ec2d 100644
--- a/src/http_body.rs
+++ b/src/http_body.rs
@@ -10,7 +10,7 @@ use std::io;
use std::io::Read;
use tokio::io::AsyncRead;
-/// Wraps hyper::Body so that it can be exposed as an AsyncRead and integrated
+/// Wraps `hyper::Body` so that it can be exposed as an `AsyncRead` and integrated
/// into resources more easily.
pub struct HttpBody {
body: Body,
@@ -19,8 +19,8 @@ pub struct HttpBody {
}
impl HttpBody {
- pub fn from(body: Body) -> HttpBody {
- HttpBody {
+ pub fn from(body: Body) -> Self {
+ Self {
body,
chunk: None,
pos: 0,
@@ -36,30 +36,27 @@ impl Read for HttpBody {
impl AsyncRead for HttpBody {
fn poll_read(&mut self, buf: &mut [u8]) -> Poll<usize, io::Error> {
- match self.chunk.take() {
- Some(chunk) => {
- debug!(
- "HttpBody Fake Read buf {} chunk {} pos {}",
- buf.len(),
- chunk.len(),
- self.pos
- );
- let n = min(buf.len(), chunk.len() - self.pos);
- {
- let rest = &chunk[self.pos..];
- buf[..n].clone_from_slice(&rest[..n]);
- }
- self.pos += n;
- if self.pos == chunk.len() {
- self.pos = 0;
- } else {
- self.chunk = Some(chunk);
- }
- return Ok(Async::Ready(n));
+ if let Some(chunk) = self.chunk.take() {
+ debug!(
+ "HttpBody Fake Read buf {} chunk {} pos {}",
+ buf.len(),
+ chunk.len(),
+ self.pos
+ );
+ let n = min(buf.len(), chunk.len() - self.pos);
+ {
+ let rest = &chunk[self.pos..];
+ buf[..n].clone_from_slice(&rest[..n]);
}
- None => {
- assert_eq!(self.pos, 0);
+ self.pos += n;
+ if self.pos == chunk.len() {
+ self.pos = 0;
+ } else {
+ self.chunk = Some(chunk);
}
+ return Ok(Async::Ready(n));
+ } else {
+ assert_eq!(self.pos, 0);
}
let p = self.body.poll_data();