fix(http1): fix response with non-chunked transfer-encoding to be close-delimited
Closes #2058
This commit is contained in:
		| @@ -800,7 +800,7 @@ impl Client { | |||||||
|                 Ok(Some((DecodedLength::CHUNKED, false))) |                 Ok(Some((DecodedLength::CHUNKED, false))) | ||||||
|             } else { |             } else { | ||||||
|                 trace!("not chunked, read till eof"); |                 trace!("not chunked, read till eof"); | ||||||
|                 Ok(Some((DecodedLength::CHUNKED, false))) |                 Ok(Some((DecodedLength::CLOSE_DELIMITED, false))) | ||||||
|             } |             } | ||||||
|         } else if let Some(len) = headers::content_length_parse_all(&inc.headers) { |         } else if let Some(len) = headers::content_length_parse_all(&inc.headers) { | ||||||
|             Ok(Some((DecodedLength::checked_new(len)?, false))) |             Ok(Some((DecodedLength::checked_new(len)?, false))) | ||||||
| @@ -1441,7 +1441,7 @@ mod tests { | |||||||
|              ", |              ", | ||||||
|         ); |         ); | ||||||
|  |  | ||||||
|         // transfer-encoding |         // transfer-encoding: chunked | ||||||
|         assert_eq!( |         assert_eq!( | ||||||
|             parse( |             parse( | ||||||
|                 "\ |                 "\ | ||||||
| @@ -1454,6 +1454,19 @@ mod tests { | |||||||
|             DecodedLength::CHUNKED |             DecodedLength::CHUNKED | ||||||
|         ); |         ); | ||||||
|  |  | ||||||
|  |         // transfer-encoding not-chunked is close-delimited | ||||||
|  |         assert_eq!( | ||||||
|  |             parse( | ||||||
|  |                 "\ | ||||||
|  |                  HTTP/1.1 200 OK\r\n\ | ||||||
|  |                  transfer-encoding: yolo\r\n\ | ||||||
|  |                  \r\n\ | ||||||
|  |                  " | ||||||
|  |             ) | ||||||
|  |             .decode, | ||||||
|  |             DecodedLength::CLOSE_DELIMITED | ||||||
|  |         ); | ||||||
|  |  | ||||||
|         // transfer-encoding and content-length = chunked |         // transfer-encoding and content-length = chunked | ||||||
|         assert_eq!( |         assert_eq!( | ||||||
|             parse( |             parse( | ||||||
|   | |||||||
| @@ -47,7 +47,7 @@ pub(crate) enum Dispatched { | |||||||
| mod body_length { | mod body_length { | ||||||
|     use std::fmt; |     use std::fmt; | ||||||
|  |  | ||||||
|     #[derive(Clone, Copy, Debug, PartialEq, Eq)] |     #[derive(Clone, Copy, PartialEq, Eq)] | ||||||
|     pub(crate) struct DecodedLength(u64); |     pub(crate) struct DecodedLength(u64); | ||||||
|  |  | ||||||
|     const MAX_LEN: u64 = ::std::u64::MAX - 2; |     const MAX_LEN: u64 = ::std::u64::MAX - 2; | ||||||
| @@ -92,6 +92,16 @@ mod body_length { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     impl fmt::Debug for DecodedLength { | ||||||
|  |         fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||
|  |             match *self { | ||||||
|  |                 DecodedLength::CLOSE_DELIMITED => f.write_str("CLOSE_DELIMITED"), | ||||||
|  |                 DecodedLength::CHUNKED => f.write_str("CHUNKED"), | ||||||
|  |                 DecodedLength(n) => f.debug_tuple("DecodedLength").field(&n).finish(), | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     impl fmt::Display for DecodedLength { |     impl fmt::Display for DecodedLength { | ||||||
|         fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |         fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||
|             match *self { |             match *self { | ||||||
|   | |||||||
| @@ -655,6 +655,35 @@ test! { | |||||||
|             body: None, |             body: None, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | test! { | ||||||
|  |     name: client_response_transfer_encoding_not_chunked, | ||||||
|  |  | ||||||
|  |     server: | ||||||
|  |         expected: "\ | ||||||
|  |             GET /te-not-chunked HTTP/1.1\r\n\ | ||||||
|  |             host: {addr}\r\n\ | ||||||
|  |             \r\n\ | ||||||
|  |             ", | ||||||
|  |         reply: "\ | ||||||
|  |             HTTP/1.1 200 OK\r\n\ | ||||||
|  |             transfer-encoding: yolo\r\n\ | ||||||
|  |             \r\n\ | ||||||
|  |             hallo\ | ||||||
|  |             ", | ||||||
|  |  | ||||||
|  |     client: | ||||||
|  |         request: { | ||||||
|  |             method: GET, | ||||||
|  |             url: "http://{addr}/te-not-chunked", | ||||||
|  |         }, | ||||||
|  |         response: | ||||||
|  |             status: OK, | ||||||
|  |             headers: { | ||||||
|  |                 "transfer-encoding" => "yolo", | ||||||
|  |             }, | ||||||
|  |             body: &b"hallo"[..], | ||||||
|  | } | ||||||
|  |  | ||||||
| test! { | test! { | ||||||
|     name: client_pipeline_responses_extra, |     name: client_pipeline_responses_extra, | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user