decode.rs
Contains an unbounded block loopRust test marker or harness
SHA-2560e9de0872534c2885617d8b648dbb052947034f081ac29371a5ba5a855e0d27e
MaleculeO(As)H₂(CmDb)Md(Pa)
Evidence
1use std::usize;
2use std::io;
3
4use futures::{Async, Poll};
5use bytes::Bytes;
6use proto::io::MemRead;
7
8use self::Kind::{Length, Chunked, Eof};
9
10/// Decoders to handle different Transfer-Encodings.
11///
12/// If a message body does not include a Transf …
38:7… unked(ChunkedState, u64),
39 /// A Reader used for responses that don't indicate a length or chunked.
40 ///
41 /// Note: This should only used for `Response`s. It is illegal for a
42 /// `Request` to be made with both `Content-Length` and
43 /// `Transfer-Encoding: chunked` missing, as explained from the spec:
44 ///
45 /// > If a Transfer-Encoding header field is present in a response and
46 // …
103:5… }
104 Chunked(ref mut state, ref mut size) => {
105 loop {
106 let mut buf = None;
107 // advances the chunked state
108 *state = try_read …
272:47… ind::InvalidInput, "Invalid chunk end LF")),
273 }
274 }
275}
276
277#[cfg(test)]
278mod tests {
279 use std::error::Error;
280 use std::io;
281 use std::io::Write;
282 use super::Decoder;
283 use super::ChunkedState;
284 use proto::io::MemRead;
285 use futures::{Async, Poll};
286 use bytes::{BytesMut, Bytes};
287 use mock::AsyncIo;
288
289 impl<'a> MemRead for &'a [u8] {
290 fn read_mem(&mut self, len: usize) -> Poll<Bytes, …
421:43… .as_ref().to_vec()).expect("decode String");
422 assert_eq!("1234567890abcdef", &result);
423 }
424
425 #[test]
426 fn test_read_chunked_after_eof() {
427 let mut mock_buf = &b"10\r\n1234567890abcdef\r\n0\ …