1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-09-22 03:20:07 +00:00

Read until eof for http/1.0 responses #771

This commit is contained in:
Nikolay Kim 2019-04-24 11:57:40 -07:00
parent 2e19f572ee
commit f429d3319f
2 changed files with 24 additions and 2 deletions

View file

@ -4,6 +4,10 @@
* Allow to render h1 request headers in `Camel-Case` * 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 ## [0.1.3] - 2019-04-23

View file

@ -300,7 +300,13 @@ impl MessageType for ResponseHead {
error!("MAX_BUFFER_SIZE unprocessed data reached, closing"); error!("MAX_BUFFER_SIZE unprocessed data reached, closing");
return Err(ParseError::TooLarge); return Err(ParseError::TooLarge);
} else { } 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))) Ok(Some((msg, decoder)))
@ -331,7 +337,7 @@ impl HeaderIndex {
} }
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq)]
/// Http payload item /// Http payload item
pub enum PayloadItem { pub enum PayloadItem {
Chunk(Bytes), Chunk(Bytes),
@ -1191,4 +1197,16 @@ mod tests {
let msg = pl.decode(&mut buf).unwrap().unwrap(); let msg = pl.decode(&mut buf).unwrap().unwrap();
assert!(msg.eof()); 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::<ResponseHead>::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")));
}
} }