mirror of
https://github.com/actix/actix-web.git
synced 2025-02-01 03:42:21 +00:00
Read until eof for http/1.0 responses #771
This commit is contained in:
parent
2e19f572ee
commit
f429d3319f
2 changed files with 24 additions and 2 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -299,8 +299,14 @@ impl MessageType for ResponseHead {
|
||||||
} else if src.len() >= MAX_BUFFER_SIZE {
|
} else if src.len() >= MAX_BUFFER_SIZE {
|
||||||
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 {
|
||||||
|
// 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 {
|
} else {
|
||||||
PayloadType::None
|
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")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue