From 3e661801976f420ec9d82a376523c0ef600884e8 Mon Sep 17 00:00:00 2001 From: huaxin Date: Thu, 19 Sep 2024 10:35:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9content-length=E7=9A=84?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E7=B1=BB=E5=9E=8B=E4=B8=BAu64=EF=BC=8C?= =?UTF-8?q?=E4=BF=9D=E8=AF=81=E5=A4=A7=E6=96=87=E4=BB=B6=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huaxin Change-Id: I8db61e7cffbbfbf66f1389c6fd3fe791dbf136fe --- ylong_http/src/body/text.rs | 11 ++++++----- ylong_http_client/src/async_impl/http_body.rs | 2 +- ylong_http_client/src/sync_impl/conn/http1.rs | 2 +- ylong_http_client/src/sync_impl/http_body.rs | 4 ++-- ylong_http_client/src/util/normalizer.rs | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ylong_http/src/body/text.rs b/ylong_http/src/body/text.rs index 5d96dbe..2c34329 100644 --- a/ylong_http/src/body/text.rs +++ b/ylong_http/src/body/text.rs @@ -276,7 +276,7 @@ impl async_impl::Body for TextBody TextBodyDecoder { + pub fn new(length: u64) -> TextBodyDecoder { TextBodyDecoder { left: length } } @@ -348,12 +348,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/http_body.rs b/ylong_http_client/src/async_impl/http_body.rs index a8fa85a..f504a6b 100644 --- a/ylong_http_client/src/async_impl/http_body.rs +++ b/ylong_http_client/src/async_impl/http_body.rs @@ -275,7 +275,7 @@ struct Text { impl Text { pub(crate) fn new( - len: usize, + len: u64, pre: &[u8], io: BoxStreamData, interceptors: Arc, diff --git a/ylong_http_client/src/sync_impl/conn/http1.rs b/ylong_http_client/src/sync_impl/conn/http1.rs index 43a5437..f92ae41 100644 --- a/ylong_http_client/src/sync_impl/conn/http1.rs +++ b/ylong_http_client/src/sync_impl/conn/http1.rs @@ -106,7 +106,7 @@ where .headers .get("Content-Length") .map(|v| v.to_string().unwrap_or(String::new())) - .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 4bafd28..1574b8d 100644 --- a/ylong_http_client/src/sync_impl/http_body.rs +++ b/ylong_http_client/src/sync_impl/http_body.rs @@ -56,7 +56,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)), } @@ -83,7 +83,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 d2d4812..00b71e8 100644 --- a/ylong_http_client/src/util/normalizer.rs +++ b/ylong_http_client/src/util/normalizer.rs @@ -162,7 +162,7 @@ impl<'a> BodyLengthParser<'a> { if content_length.is_some() { let content_length_valid = content_length .and_then(|v| v.to_string().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, @@ -180,7 +180,7 @@ impl<'a> BodyLengthParser<'a> { pub(crate) enum BodyLength { #[cfg(feature = "http1_1")] Chunk, - Length(usize), + Length(u64), Empty, UntilClose, } -- Gitee