1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-27 12:01:15 +00:00

Merge pull request #496 from Neopallium/master

Fix issue with 'Connection: close' in ClientRequest
This commit is contained in:
Nikolay Kim 2018-08-31 17:17:39 -07:00 committed by GitHub
commit e59abfd716
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 30 deletions

View file

@ -38,19 +38,9 @@ impl HttpResponseParser {
where where
T: IoStream, T: IoStream,
{ {
// if buf is empty parse_message will always return NotReady, let's avoid that
if buf.is_empty() {
match io.read_available(buf) {
Ok(Async::Ready((_, true))) => {
return Err(HttpResponseParserError::Disconnect)
}
Ok(Async::Ready((_, false))) => (),
Ok(Async::NotReady) => return Ok(Async::NotReady),
Err(err) => return Err(HttpResponseParserError::Error(err.into())),
}
}
loop { loop {
// Don't call parser until we have data to parse.
if !buf.is_empty() {
match HttpResponseParser::parse_message(buf) match HttpResponseParser::parse_message(buf)
.map_err(HttpResponseParserError::Error)? .map_err(HttpResponseParserError::Error)?
{ {
@ -62,11 +52,16 @@ impl HttpResponseParser {
if buf.capacity() >= MAX_BUFFER_SIZE { if buf.capacity() >= MAX_BUFFER_SIZE {
return Err(HttpResponseParserError::Error(ParseError::TooLarge)); return Err(HttpResponseParserError::Error(ParseError::TooLarge));
} }
// Parser needs more data.
}
}
}
// Read some more data into the buffer for the parser.
match io.read_available(buf) { match io.read_available(buf) {
Ok(Async::Ready((_, true))) => { Ok(Async::Ready((false, true))) => {
return Err(HttpResponseParserError::Disconnect) return Err(HttpResponseParserError::Disconnect)
} }
Ok(Async::Ready((_, false))) => (), Ok(Async::Ready(_)) => (),
Ok(Async::NotReady) => return Ok(Async::NotReady), Ok(Async::NotReady) => return Ok(Async::NotReady),
Err(err) => { Err(err) => {
return Err(HttpResponseParserError::Error(err.into())) return Err(HttpResponseParserError::Error(err.into()))
@ -74,8 +69,6 @@ impl HttpResponseParser {
} }
} }
} }
}
}
pub fn parse_payload<T>( pub fn parse_payload<T>(
&mut self, io: &mut T, buf: &mut BytesMut, &mut self, io: &mut T, buf: &mut BytesMut,

View file

@ -66,6 +66,16 @@ fn test_simple() {
assert_eq!(bytes, Bytes::from_static(STR.as_ref())); assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
} }
#[test]
fn test_connection_close() {
let mut srv =
test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok().body(STR)));
let request = srv.get().header("Connection", "close").finish().unwrap();
let response = srv.execute(request.send()).unwrap();
assert!(response.status().is_success());
}
#[test] #[test]
fn test_with_query_parameter() { fn test_with_query_parameter() {
let mut srv = test::TestServer::new(|app| { let mut srv = test::TestServer::new(|app| {