From 523b890a19e9325938adf42456eea6191fcb8029 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Sat, 6 Aug 2016 00:10:46 -0700 Subject: [PATCH] fix(server): support HTTP/1.1 pipelining --- src/http/conn.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/http/conn.rs b/src/http/conn.rs index 187d7c6c2c..8fa4caba6b 100644 --- a/src/http/conn.rs +++ b/src/http/conn.rs @@ -117,10 +117,16 @@ impl> ConnInner { } fn parse(&mut self) -> ::Result>::Message as Http1Message>::Incoming>> { - let n = try!(self.buf.read_from(&mut self.transport)); - if n == 0 { - trace!("parse eof"); - return Err(io::Error::new(io::ErrorKind::UnexpectedEof, "parse eof").into()); + match self.buf.read_from(&mut self.transport) { + Ok(0) => { + trace!("parse eof"); + return Err(io::Error::new(io::ErrorKind::UnexpectedEof, "parse eof").into()); + } + Ok(_) => {}, + Err(e) => match e.kind() { + io::ErrorKind::WouldBlock => {}, + _ => return Err(e.into()) + } } match try!(http::parse::<>::Message, _>(self.buf.bytes())) { Some((head, len)) => { @@ -444,9 +450,9 @@ impl> ConnInner { state } - fn can_read_more(&self) -> bool { + fn can_read_more(&self, was_init: bool) -> bool { match self.state { - State::Init { .. } => false, + State::Init { .. } => !was_init && !self.buf.is_empty(), _ => !self.buf.is_empty() } } @@ -549,6 +555,11 @@ impl> Conn { events }; + let was_init = match self.0.state { + State::Init { .. } => true, + _ => false + }; + if events.is_readable() { self.0.on_readable(scope); } @@ -570,7 +581,7 @@ impl> Conn { }, }; - if events.is_readable() && self.0.can_read_more() { + if events.is_readable() && self.0.can_read_more(was_init) { return self.ready(events, scope); }