diff --git a/ylong_http/src/body/text.rs b/ylong_http/src/body/text.rs index dc2e0468bf7af4d5ebf092e0483e0664885f1556..58010d6c5554ce773653bd0cf0c17f11480782d1 100644 --- a/ylong_http/src/body/text.rs +++ b/ylong_http/src/body/text.rs @@ -306,7 +306,7 @@ impl async_impl::Body for TextBody> { /// assert_eq!(left, b"[REDUNDANT DATA]"); /// ``` pub struct TextBodyDecoder { - left: usize, + left: u64, } impl TextBodyDecoder { @@ -321,7 +321,7 @@ impl TextBodyDecoder { /// /// let decoder = TextBodyDecoder::new(10); /// ``` - pub fn new(length: usize) -> TextBodyDecoder { + pub fn new(length: u64) -> TextBodyDecoder { TextBodyDecoder { left: length } } @@ -378,12 +378,13 @@ impl TextBodyDecoder { return (Text::complete(&buf[..0]), buf); } - let size = min(self.left, buf.len()); + let size = min(self.left, buf.len() as u64); self.left -= size; + let end = size as usize; if self.left == 0 { - (Text::complete(&buf[..size]), &buf[size..]) + (Text::complete(&buf[..end]), &buf[end..]) } else { - (Text::partial(&buf[..size]), &buf[size..]) + (Text::partial(&buf[..end]), &buf[end..]) } } } diff --git a/ylong_http_client/src/async_impl/conn/http2.rs b/ylong_http_client/src/async_impl/conn/http2.rs index 94c755aad400027d48cc98d72fb154bf9330e63c..1d5bf3302f893092311a6633e06969d0bf836d44 100644 --- a/ylong_http_client/src/async_impl/conn/http2.rs +++ b/ylong_http_client/src/async_impl/conn/http2.rs @@ -144,7 +144,7 @@ where .headers .get("Content-Length") .map(|v| v.to_str().unwrap_or(String::new())) - .and_then(|s| s.parse::().ok()); + .and_then(|s| s.parse::().ok()); match content_length { None => HttpBody::empty(), Some(0) => HttpBody::empty(), diff --git a/ylong_http_client/src/async_impl/http_body.rs b/ylong_http_client/src/async_impl/http_body.rs index 0acbb182d73722a600a12827869730de8f947be4..669f7377561fef6c3514c1a566b2b388f1cede09 100644 --- a/ylong_http_client/src/async_impl/http_body.rs +++ b/ylong_http_client/src/async_impl/http_body.rs @@ -99,7 +99,7 @@ impl HttpBody { } #[cfg(feature = "http2")] - pub(crate) fn text(len: usize, pre: &[u8], io: BoxStreamData) -> Self { + pub(crate) fn text(len: u64, pre: &[u8], io: BoxStreamData) -> Self { Self { kind: Kind::Text(Text::new(len, pre, io)), sleep: None, @@ -283,7 +283,7 @@ struct Text { } impl Text { - pub(crate) fn new(len: usize, pre: &[u8], io: BoxStreamData) -> Self { + pub(crate) fn new(len: u64, pre: &[u8], io: BoxStreamData) -> Self { Self { decoder: TextBodyDecoder::new(len), pre: (!pre.is_empty()).then_some(Cursor::new(pre.to_vec())), diff --git a/ylong_http_client/src/sync_impl/conn/http1.rs b/ylong_http_client/src/sync_impl/conn/http1.rs index bfa41f7fcda02340131779d52a26b166d046ba8b..ef89318b47cd8fe91f65a4c3c2889d8aa0ab63c8 100644 --- a/ylong_http_client/src/sync_impl/conn/http1.rs +++ b/ylong_http_client/src/sync_impl/conn/http1.rs @@ -107,7 +107,7 @@ where .headers .get("Content-Length") .map(|v| v.to_str().unwrap_or_default()) - .and_then(|s| s.parse::().ok()); + .and_then(|s| s.parse::().ok()); let is_trailer = part.headers.get("Trailer").is_some(); diff --git a/ylong_http_client/src/sync_impl/http_body.rs b/ylong_http_client/src/sync_impl/http_body.rs index 37ecaa7128e7c83c25a65ecfa29f27a60fdd23a0..c7b13174b91713c1153f23a1dd71db43f6199a0b 100644 --- a/ylong_http_client/src/sync_impl/http_body.rs +++ b/ylong_http_client/src/sync_impl/http_body.rs @@ -57,7 +57,7 @@ impl HttpBody { Self { kind: Kind::Empty } } - pub(crate) fn text(len: usize, pre: &[u8], io: BoxStreamData) -> Self { + pub(crate) fn text(len: u64, pre: &[u8], io: BoxStreamData) -> Self { Self { kind: Kind::Text(Text::new(len, pre, io)), } @@ -84,7 +84,7 @@ struct Text { } impl Text { - pub(crate) fn new(len: usize, pre: &[u8], io: BoxStreamData) -> Self { + pub(crate) fn new(len: u64, pre: &[u8], io: BoxStreamData) -> Self { Self { decoder: TextBodyDecoder::new(len), pre: (!pre.is_empty()).then_some(Cursor::new(pre.to_vec())), diff --git a/ylong_http_client/src/util/normalizer.rs b/ylong_http_client/src/util/normalizer.rs index d187489688c227bebccfcece4dce4abe5092df0b..13e432025347581ec2dfe4496003064b4faf1ebb 100644 --- a/ylong_http_client/src/util/normalizer.rs +++ b/ylong_http_client/src/util/normalizer.rs @@ -158,7 +158,7 @@ impl<'a> BodyLengthParser<'a> { if content_length.is_some() { let content_length_valid = content_length .and_then(|v| v.to_str().ok()) - .and_then(|s| s.parse::().ok()); + .and_then(|s| s.parse::().ok()); return match content_length_valid { // If `content-length` is 0, the io stream cannot be read, @@ -179,7 +179,7 @@ impl<'a> BodyLengthParser<'a> { pub(crate) enum BodyLength { #[cfg(feature = "http1_1")] Chunk, - Length(usize), + Length(u64), Empty, UntilClose, }