From f88f1c65b6f9dab810c41aa52c5059838941356f Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 8 Mar 2018 18:19:46 -0800 Subject: [PATCH] update tests --- src/payload.rs | 8 ++++---- src/ws/frame.rs | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/payload.rs b/src/payload.rs index 5fd960976..bfa4dc81f 100644 --- a/src/payload.rs +++ b/src/payload.rs @@ -341,8 +341,8 @@ impl PayloadHelper where S: Stream { let mut len = 0; while len < size { let mut chunk = self.items.pop_front().unwrap(); - let rem = cmp::min(size - len, chunk.len()); - len -= rem; + let rem = cmp::min(size-len, chunk.len()); + len += rem; if rem < chunk.len() { chunk.split_to(rem); self.items.push_front(chunk); @@ -546,11 +546,11 @@ mod tests { sender.feed_data(Bytes::from("line1")); sender.feed_data(Bytes::from("line2")); - assert_eq!(Async::Ready(Some(BytesMut::from("li"))), + assert_eq!(Async::Ready(Some(Bytes::from_static(b"li"))), payload.readexactly(2).ok().unwrap()); assert_eq!(payload.len, 3); - assert_eq!(Async::Ready(Some(BytesMut::from("ne1l"))), + assert_eq!(Async::Ready(Some(Bytes::from_static(b"ne1l"))), payload.readexactly(4).ok().unwrap()); assert_eq!(payload.len, 4); diff --git a/src/ws/frame.rs b/src/ws/frame.rs index c4841ce7e..1d7582986 100644 --- a/src/ws/frame.rs +++ b/src/ws/frame.rs @@ -132,6 +132,11 @@ impl Frame { pl.drop_payload(idx); // get body + if length == 0 { + return Ok(Async::Ready(Some(Frame { + finished, rsv1, rsv2, rsv3, opcode, payload: Binary::from("") }))); + } + let data = match pl.readexactly(length)? { Async::Ready(Some(buf)) => buf, Async::Ready(None) => return Ok(Async::Ready(None)),