Skip to content

Commit dc11a5a

Browse files
committed
feat(decompression-plz): added shortcircuit if only identity
1 parent 4222cbd commit dc11a5a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

decompression-plz/src/state.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use body_plz::variants::Body;
22
use bytes::BytesMut;
3-
use header_plz::body_headers::encoding_info::EncodingInfo;
3+
use header_plz::body_headers::{
4+
content_encoding::ContentEncoding, encoding_info::EncodingInfo,
5+
};
46

57
use crate::{
68
decode_struct::DecodeStruct,
@@ -59,7 +61,6 @@ where
5961
if last_info.encodings().is_empty() {
6062
ds.message
6163
.remove_header_on_position(last_info.header_index);
62-
6364
// remove the last encoding_info
6465
encoding_infos.pop();
6566
}
@@ -139,6 +140,12 @@ fn apply_encoding<T>(
139140
where
140141
T: DecompressTrait + std::fmt::Debug,
141142
{
143+
if is_only_encoding(encoding_info, ContentEncoding::Identity) {
144+
decode_struct
145+
.message
146+
.remove_header_on_position(encoding_info[0].header_index);
147+
return Ok(());
148+
}
142149
match decompression_runner(
143150
&decode_struct.body,
144151
decode_struct.extra_body.as_deref(),
@@ -202,3 +209,12 @@ where
202209
}
203210
}
204211
}
212+
213+
pub fn is_only_encoding(
214+
encoding_info: &[EncodingInfo],
215+
encoding: ContentEncoding,
216+
) -> bool {
217+
encoding_info.len() == 1
218+
&& encoding_info[0].encodings().len() == 1
219+
&& encoding_info[0].encodings()[0] == encoding
220+
}

0 commit comments

Comments
 (0)