@@ -13,6 +13,8 @@ use crate::{
1313 } ,
1414} ;
1515
16+ #[ cfg_attr( test, derive( PartialEq ) ) ]
17+ #[ derive( Debug ) ]
1618pub enum DecodeState < ' a , T > {
1719 Start ( DecodeStruct < ' a , T > ) ,
1820 TransferEncoding ( DecodeStruct < ' a , T > , Vec < EncodingInfo > ) ,
@@ -178,13 +180,76 @@ where
178180#[ cfg( test) ]
179181mod tests {
180182
181- use crate :: decompress;
182- use crate :: decompress_trait:: DecompressTrait ;
183183 use body_plz:: variants:: Body ;
184- use header_plz:: InfoLine ;
185- use header_plz:: Request ;
186- use header_plz:: body_headers:: parse:: ParseBodyHeaders ;
187- use header_plz:: message_head:: MessageHead ;
184+ use bytes:: BytesMut ;
185+ use header_plz:: {
186+ HeaderMap , abnf:: HEADER_DELIMITER , body_headers:: BodyHeader ,
187+ message_head:: MessageHead ,
188+ } ;
188189
189- use super :: * ;
190+ use crate :: { DecompressTrait , state:: DecodeState , tests:: INPUT } ;
191+
192+ #[ derive( Debug , PartialEq ) ]
193+ struct TestMessage {
194+ header_map : HeaderMap ,
195+ body_header : Option < BodyHeader > ,
196+ body : Option < Body > ,
197+ extra_body : Option < BytesMut > ,
198+ }
199+
200+ impl DecompressTrait for TestMessage {
201+ fn get_body ( & mut self ) -> Body {
202+ self . body . take ( ) . unwrap ( )
203+ }
204+
205+ fn get_extra_body ( & mut self ) -> Option < BytesMut > {
206+ self . extra_body . take ( )
207+ }
208+
209+ fn set_body ( & mut self , body : Body ) {
210+ self . body = Some ( body) ;
211+ }
212+
213+ fn body_headers_as_mut ( & mut self ) -> & mut Option < BodyHeader > {
214+ & mut self . body_header
215+ }
216+
217+ fn header_map ( & self ) -> & HeaderMap {
218+ self . header_map ( )
219+ }
220+
221+ fn header_map_as_mut ( & mut self ) -> & mut HeaderMap {
222+ self . header_map_as_mut ( )
223+ }
224+ }
225+
226+ impl TestMessage {
227+ fn build (
228+ headers : BytesMut ,
229+ body : Body ,
230+ extra : Option < BytesMut > ,
231+ ) -> Self {
232+ let header_map = HeaderMap :: from ( headers) ;
233+ let body_header = BodyHeader :: from ( & header_map) ;
234+ Self {
235+ header_map,
236+ body_header : Some ( body_header) ,
237+ body : Some ( body) ,
238+ extra_body : extra,
239+ }
240+ }
241+ }
242+
243+ #[ test]
244+ fn test_decode_init_no_te_or_ce ( ) {
245+ let headers = "Host: example.com\r \n \
246+ Content-Type: text/html; charset=utf-8\r \n \
247+ Content-Length: 11\r \n \r \n ";
248+ let mut tm =
249+ TestMessage :: build ( headers. into ( ) , Body :: Raw ( INPUT . into ( ) ) , None ) ;
250+ let mut buf = BytesMut :: new ( ) ;
251+ let mut state = DecodeState :: init ( & mut tm, & mut buf) ;
252+ state = state. try_next ( ) . unwrap ( ) ;
253+ assert ! ( matches!( state, DecodeState :: End ) ) ;
254+ }
190255}
0 commit comments