修改content-length的存储类型为u64,保证大文件可以正常下载

Signed-off-by: huaxin <huaxin5@huawei.com>
Change-Id: I8db61e7cffbbfbf66f1389c6fd3fe791dbf136fe
This commit is contained in:
huaxin 2024-09-19 10:35:09 +08:00
parent bbed43fa11
commit 3e66180197
5 changed files with 12 additions and 11 deletions

View File

@ -276,7 +276,7 @@ impl<T: AsyncRead + Unpin + Send + Sync> async_impl::Body for TextBody<FromAsync
/// assert_eq!(left, b"[REDUNDANT DATA]");
/// ```
pub struct TextBodyDecoder {
left: usize,
left: u64,
}
impl TextBodyDecoder {
@ -291,7 +291,7 @@ impl TextBodyDecoder {
///
/// let decoder = TextBodyDecoder::new(10);
/// ```
pub fn new(length: usize) -> 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..])
}
}
}

View File

@ -275,7 +275,7 @@ struct Text {
impl Text {
pub(crate) fn new(
len: usize,
len: u64,
pre: &[u8],
io: BoxStreamData,
interceptors: Arc<Interceptors>,

View File

@ -106,7 +106,7 @@ where
.headers
.get("Content-Length")
.map(|v| v.to_string().unwrap_or(String::new()))
.and_then(|s| s.parse::<usize>().ok());
.and_then(|s| s.parse::<u64>().ok());
let is_trailer = part.headers.get("Trailer").is_some();

View File

@ -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())),

View File

@ -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::<usize>().ok());
.and_then(|s| s.parse::<u64>().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,
}