feat(body): change Payload::Data to be a Buf

Closes #1508

BREAKING CHANGE: Each payload chunk must implement `Buf`, instead of
  just `AsRef<[u8]>`.
This commit is contained in:
Sean McArthur
2018-05-07 10:06:28 -07:00
parent dfa7e17960
commit a3be110a55
6 changed files with 34 additions and 30 deletions

View File

@@ -1,4 +1,4 @@
use bytes::Bytes;
use bytes::{Buf, Bytes};
use futures::{Async, Future, Poll, Stream};
use http::{Request, Response, StatusCode};
use tokio_io::{AsyncRead, AsyncWrite};
@@ -241,7 +241,7 @@ where
if self.conn.can_write_body() {
self.conn.write_body(Some(chunk)).map_err(::Error::new_body_write)?;
// This allows when chunk is `None`, or `Some([])`.
} else if chunk.as_ref().len() == 0 {
} else if chunk.remaining() == 0 {
// ok
} else {
warn!("unexpected chunk when body cannot write");