Skip to content

Commit dfc68fb

Browse files
committed
feat(decompression-plz): added new UpdateContentLengthAndErr state for DecodeState
1 parent 8f9641b commit dfc68fb

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

decompression-plz/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
use bytes::BytesMut;
44

5-
use crate::{
6-
decompression::multi::error::MultiDecompressErrorReason,
7-
state::DecodeState,
8-
};
5+
use crate::state::DecodeState;
96
pub mod chunked;
107
pub mod content_length;
8+
pub use decompression::multi::error::MultiDecompressErrorReason;
119
mod decode_struct;
1210
mod decompress_trait;
1311
mod decompression;

decompression-plz/src/state.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub enum DecodeState<'a, T> {
1818
TransferEncoding(DecodeStruct<'a, T>, Vec<EncodingInfo>),
1919
ContentEncoding(DecodeStruct<'a, T>, Vec<EncodingInfo>),
2020
UpdateContentLength(DecodeStruct<'a, T>),
21+
UpdateContentLengthAndErr(DecodeStruct<'a, T>, MultiDecompressErrorReason),
2122
End,
2223
}
2324

@@ -66,12 +67,11 @@ where
6667
}
6768
Ok(()) => Self::UpdateContentLength(decode_struct),
6869
Err(e) => {
69-
// TODO: remove chunked TE
70-
error!("{}", e);
70+
// TODO: maybe remove chunked TE
7171
if e.is_partial() {
72-
Self::UpdateContentLength(decode_struct)
72+
Self::UpdateContentLengthAndErr(decode_struct, e)
7373
} else {
74-
Self::End
74+
return Err(e);
7575
}
7676
}
7777
};
@@ -81,19 +81,27 @@ where
8181
mut decode_struct,
8282
mut encoding_infos,
8383
) => {
84-
match apply_encoding(&mut decode_struct, &mut encoding_infos) {
85-
Err(e) if !e.is_partial() => {
86-
error!("{}", e);
87-
return Ok(Self::End);
84+
let next_state = if let Err(e) =
85+
apply_encoding(&mut decode_struct, &mut encoding_infos)
86+
{
87+
if e.is_partial() {
88+
Self::UpdateContentLengthAndErr(decode_struct, e)
89+
} else {
90+
return Err(e);
8891
}
89-
_ => {}
90-
}
91-
Ok(Self::UpdateContentLength(decode_struct))
92+
} else {
93+
Self::UpdateContentLength(decode_struct)
94+
};
95+
Ok(next_state)
9296
}
9397
DecodeState::UpdateContentLength(mut decode_struct) => {
9498
decode_struct.add_body_and_update_cl();
9599
Ok(Self::End)
96100
}
101+
DecodeState::UpdateContentLengthAndErr(mut decode_struct, e) => {
102+
decode_struct.add_body_and_update_cl();
103+
Err(e)
104+
}
97105
DecodeState::End => Ok(Self::End),
98106
}
99107
}

0 commit comments

Comments
 (0)