Skip to content

Commit

Permalink
fix(client): improve keep-alive of bodyless Responses
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Aug 5, 2015
1 parent 31f117e commit 67c284a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/client/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ impl Response {
version: version,
headers: headers,
url: url,
message: message,
status_raw: raw_status,
is_drained: false,
is_drained: !message.has_body(),
message: message,
})
}

Expand Down
7 changes: 7 additions & 0 deletions src/http/h1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ impl HttpMessage for Http11Message {
})
}

fn has_body(&self) -> bool {
match self.reader {
Some(EmptyReader(..)) => false,
_ => true
}
}

#[cfg(feature = "timeouts")]
#[inline]
fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()> {
Expand Down
4 changes: 4 additions & 0 deletions src/http/h2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ impl<S> HttpMessage for Http2Message<S> where S: CloneableStream {
Ok(head)
}

fn has_body(&self) -> bool {
true
}

#[cfg(feature = "timeouts")]
#[inline]
fn set_read_timeout(&self, _dur: Option<Duration>) -> io::Result<()> {
Expand Down
2 changes: 2 additions & 0 deletions src/http/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub trait HttpMessage: Write + Read + Send + Any + Typeable + Debug {
fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()>;
/// Closes the underlying HTTP connection.
fn close_connection(&mut self) -> ::Result<()>;
/// Returns whether the incoming message has a body.
fn has_body(&self) -> bool;
}

impl HttpMessage {
Expand Down

0 comments on commit 67c284a

Please sign in to comment.