deal with http/1.0 and connection closed
This commit is contained in:
@@ -250,13 +250,23 @@ impl Response {
|
|||||||
pub fn into_reader(self) -> impl Read {
|
pub fn into_reader(self) -> impl Read {
|
||||||
//
|
//
|
||||||
|
|
||||||
let is_chunked = self.header("transfer-encoding")
|
let is_http10 = self.http_version().eq_ignore_ascii_case("HTTP/1.0");
|
||||||
.map(|enc| enc.len() > 0) // whatever it says, do chunked
|
let is_close = self
|
||||||
|
.header("connection")
|
||||||
|
.map(|c| c.eq_ignore_ascii_case("close"))
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
let is_head = (&self.unit).as_ref().map(|u| u.is_head).unwrap_or(false);
|
let is_head = (&self.unit).as_ref().map(|u| u.is_head).unwrap_or(false);
|
||||||
|
|
||||||
let len = if is_head {
|
let is_chunked = self.header("transfer-encoding")
|
||||||
|
.map(|enc| enc.len() > 0) // whatever it says, do chunked
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
let use_chunked = !is_http10 && !is_head && is_chunked;
|
||||||
|
|
||||||
|
let expected_bytes = if is_http10 || is_close {
|
||||||
|
None
|
||||||
|
} else if is_head {
|
||||||
// head requests never have a body
|
// head requests never have a body
|
||||||
Some(0)
|
Some(0)
|
||||||
} else {
|
} else {
|
||||||
@@ -269,7 +279,7 @@ impl Response {
|
|||||||
let yolo = YoloRead { stream: stream_ptr };
|
let yolo = YoloRead { stream: stream_ptr };
|
||||||
let unit = self.unit;
|
let unit = self.unit;
|
||||||
|
|
||||||
match (is_chunked && !is_head, len) {
|
match (use_chunked, expected_bytes) {
|
||||||
(true, _) => Box::new(PoolReturnRead::new(
|
(true, _) => Box::new(PoolReturnRead::new(
|
||||||
unit,
|
unit,
|
||||||
stream_ptr,
|
stream_ptr,
|
||||||
|
|||||||
Reference in New Issue
Block a user