diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index c51b421c3..78245692f 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -4,6 +4,10 @@ * Allow to render h1 request headers in `Camel-Case` +### Fixed + +* Read until eof for http/1.0 responses #771 + ## [0.1.3] - 2019-04-23 diff --git a/actix-http/src/h1/decoder.rs b/actix-http/src/h1/decoder.rs index 411649fc1..12419d665 100644 --- a/actix-http/src/h1/decoder.rs +++ b/actix-http/src/h1/decoder.rs @@ -300,7 +300,13 @@ impl MessageType for ResponseHead { error!("MAX_BUFFER_SIZE unprocessed data reached, closing"); return Err(ParseError::TooLarge); } else { - PayloadType::None + // for HTTP/1.0 read to eof and close connection + if msg.version == Version::HTTP_10 { + msg.set_connection_type(ConnectionType::Close); + PayloadType::Payload(PayloadDecoder::eof()) + } else { + PayloadType::None + } }; Ok(Some((msg, decoder))) @@ -331,7 +337,7 @@ impl HeaderIndex { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] /// Http payload item pub enum PayloadItem { Chunk(Bytes), @@ -1191,4 +1197,16 @@ mod tests { let msg = pl.decode(&mut buf).unwrap().unwrap(); assert!(msg.eof()); } + + #[test] + fn test_response_http10_read_until_eof() { + let mut buf = BytesMut::from(&"HTTP/1.0 200 Ok\r\n\r\ntest data"[..]); + + let mut reader = MessageDecoder::::default(); + let (_msg, pl) = reader.decode(&mut buf).unwrap().unwrap(); + let mut pl = pl.unwrap(); + + let chunk = pl.decode(&mut buf).unwrap().unwrap(); + assert_eq!(chunk, PayloadItem::Chunk(Bytes::from_static(b"test data"))); + } }