Skip to content

Commit

Permalink
fix(server): support HTTP/1.1 pipelining
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Aug 6, 2016
1 parent 12dac9b commit 523b890
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/http/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,16 @@ impl<K: Key, T: Transport, H: MessageHandler<T>> ConnInner<K, T, H> {
}

fn parse(&mut self) -> ::Result<http::MessageHead<<<H as MessageHandler<T>>::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::<<H as MessageHandler<T>>::Message, _>(self.buf.bytes())) {
Some((head, len)) => {
Expand Down Expand Up @@ -444,9 +450,9 @@ impl<K: Key, T: Transport, H: MessageHandler<T>> ConnInner<K, T, H> {
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()
}
}
Expand Down Expand Up @@ -549,6 +555,11 @@ impl<K: Key, T: Transport, H: MessageHandler<T>> Conn<K, T, H> {
events
};

let was_init = match self.0.state {
State::Init { .. } => true,
_ => false
};

if events.is_readable() {
self.0.on_readable(scope);
}
Expand All @@ -570,7 +581,7 @@ impl<K: Key, T: Transport, H: MessageHandler<T>> Conn<K, T, H> {
},
};

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);
}

Expand Down

0 comments on commit 523b890

Please sign in to comment.