11#![ allow( warnings, unused) ]
22
33use bytes:: BytesMut ;
4- use header_plz:: body_headers:: BodyHeader ;
4+ use header_plz:: body_headers:: { BodyHeader , encoding_info :: EncodingInfo } ;
55
66use crate :: {
77 content_length:: add_body_and_update_cl,
8- decompression:: multi:: error:: MultiDecompressErrorReason , state:: runner,
8+ decompression:: multi:: error:: {
9+ MultiDecompressError , MultiDecompressErrorReason ,
10+ } ,
11+ dtraits:: DecompressTrait ,
12+ encoding_type:: EncodingType ,
13+ state:: runner,
914} ;
1015mod content_length;
1116pub mod decompression;
1217pub mod dstruct;
1318pub mod dtraits;
19+ mod encoding_type;
1420mod error;
1521mod state;
1622
@@ -20,72 +26,54 @@ pub fn decompress<T>(
2026 buf : & mut BytesMut ,
2127) -> Result < ( ) , error:: DecompressErrorStruct >
2228where
23- T : dtraits :: DecompressTrait ,
29+ T : DecompressTrait ,
2430{
2531 let mut body = message. get_body ( ) . into_bytes ( ) . unwrap ( ) ;
2632 let mut body_headers = message. body_headers_as_mut ( ) . take ( ) ;
2733
28- //
29- if let Some ( BodyHeader {
30- transfer_encoding : Some ( einfo_list) ,
31- ..
32- } ) = body_headers. as_mut ( )
33- {
34- match runner ( & body, extra_body. as_deref ( ) , einfo_list, buf) {
35- Ok ( state) => {
36- ( body, extra_body) = state. into ( ) ;
37- }
38- Err ( e) => {
39- eprintln ! ( "{:?}" , e) ;
40- match e. reason {
41- MultiDecompressErrorReason :: Partial {
42- partial_body,
43- header_index,
44- compression_index,
45- } => {
46- todo ! ( )
47- }
48- _ => {
49- return Ok ( ( ) ) ;
50- }
51- }
52- }
53- }
54- }
34+ apply_encoding (
35+ & mut message,
36+ EncodingType :: TransferEncoding ,
37+ body_headers. as_mut ( ) ,
38+ & body,
39+ extra_body. as_deref ( ) ,
40+ buf,
41+ ) ;
5542
56- //
57- if let Some ( BodyHeader {
58- content_encoding : Some ( einfo_list) ,
59- ..
60- } ) = body_headers. as_mut ( )
61- {
62- match runner ( & body, extra_body. as_deref ( ) , einfo_list, buf) {
63- Ok ( state) => {
64- ( body, extra_body) = state. into ( ) ;
65- }
66- Err ( e) => {
67- eprintln ! ( "{:?}" , e) ;
68- match e. reason {
69- MultiDecompressErrorReason :: Partial {
70- partial_body,
71- header_index,
72- compression_index,
73- } => {
74- todo ! ( )
75- }
76- _ => {
77- return Ok ( ( ) ) ;
78- }
79- }
80- }
81- }
82- }
43+ apply_encoding (
44+ & mut message,
45+ EncodingType :: ContentEncoding ,
46+ body_headers. as_mut ( ) ,
47+ & body,
48+ extra_body. as_deref ( ) ,
49+ buf,
50+ ) ;
8351
8452 //
8553 add_body_and_update_cl ( & mut message, body, body_headers) ;
8654 Ok ( ( ) )
8755}
8856
57+ fn apply_encoding < T > (
58+ message : & mut T ,
59+ encoding_type : EncodingType ,
60+ body_headers : Option < & mut BodyHeader > ,
61+ body : & [ u8 ] ,
62+ extra_body : Option < & [ u8 ] > ,
63+ buf : & mut BytesMut ,
64+ ) -> Result < ( ) , MultiDecompressError >
65+ where
66+ T : DecompressTrait ,
67+ {
68+ if let Some ( einfo_list) = encoding_type. encoding_info ( body_headers) {
69+ match runner ( & body, extra_body. as_deref ( ) , einfo_list, buf) {
70+ Ok ( _) => todo ! ( ) ,
71+ Err ( _) => todo ! ( ) ,
72+ }
73+ } ;
74+ Ok ( ( ) )
75+ }
76+
8977// helper function for tests
9078#[ cfg( test) ]
9179pub mod tests {
0 commit comments