Skip to content

Commit 67c284a

Browse files
committed
fix(client): improve keep-alive of bodyless Responses
1 parent 31f117e commit 67c284a

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/client/response.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ impl Response {
4747
version: version,
4848
headers: headers,
4949
url: url,
50-
message: message,
5150
status_raw: raw_status,
52-
is_drained: false,
51+
is_drained: !message.has_body(),
52+
message: message,
5353
})
5454
}
5555

src/http/h1.rs

+7
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ impl HttpMessage for Http11Message {
203203
})
204204
}
205205

206+
fn has_body(&self) -> bool {
207+
match self.reader {
208+
Some(EmptyReader(..)) => false,
209+
_ => true
210+
}
211+
}
212+
206213
#[cfg(feature = "timeouts")]
207214
#[inline]
208215
fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()> {

src/http/h2.rs

+4
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ impl<S> HttpMessage for Http2Message<S> where S: CloneableStream {
400400
Ok(head)
401401
}
402402

403+
fn has_body(&self) -> bool {
404+
true
405+
}
406+
403407
#[cfg(feature = "timeouts")]
404408
#[inline]
405409
fn set_read_timeout(&self, _dur: Option<Duration>) -> io::Result<()> {

src/http/message.rs

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ pub trait HttpMessage: Write + Read + Send + Any + Typeable + Debug {
7272
fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()>;
7373
/// Closes the underlying HTTP connection.
7474
fn close_connection(&mut self) -> ::Result<()>;
75+
/// Returns whether the incoming message has a body.
76+
fn has_body(&self) -> bool;
7577
}
7678

7779
impl HttpMessage {

0 commit comments

Comments
 (0)