@@ -110,7 +110,7 @@ where
110110 decode_struct. add_body_and_update_cl ( ) ;
111111 Err ( e)
112112 }
113- DecodeState :: End => Ok ( Self :: End ) ,
113+ DecodeState :: End => Ok ( DecodeState :: End ) ,
114114 }
115115 }
116116
@@ -221,11 +221,11 @@ mod tests {
221221 }
222222
223223 fn header_map ( & self ) -> & HeaderMap {
224- self . header_map ( )
224+ & self . header_map
225225 }
226226
227227 fn header_map_as_mut ( & mut self ) -> & mut HeaderMap {
228- self . header_map_as_mut ( )
228+ & mut self . header_map
229229 }
230230 }
231231
@@ -244,18 +244,57 @@ mod tests {
244244 extra_body : extra,
245245 }
246246 }
247+
248+ fn into_bytes ( self ) -> BytesMut {
249+ let mut bytes = self . header_map . into_bytes ( ) ;
250+ bytes. unsplit ( self . body . unwrap ( ) . into_bytes ( ) . unwrap ( ) ) ;
251+ bytes
252+ }
247253 }
248254
249255 #[ test]
250- fn test_decode_init_no_te_or_ce ( ) {
256+ fn test_decode_init_no_enc ( ) {
251257 let headers = "Host: example.com\r \n \
252258 Content-Type: text/html; charset=utf-8\r \n \
253259 Content-Length: 11\r \n \r \n ";
254260 let mut tm =
255261 TestMessage :: build ( headers. into ( ) , Body :: Raw ( INPUT . into ( ) ) , None ) ;
256262 let mut buf = BytesMut :: new ( ) ;
257263 let mut state = DecodeState :: init ( & mut tm, & mut buf) ;
264+ dbg ! ( & state) ;
265+ state = state. try_next ( ) . unwrap ( ) ;
266+ dbg ! ( & state) ;
267+ assert ! ( matches!( state, DecodeState :: End ) ) ;
268+ let result = tm. into_bytes ( ) ;
269+ let verify = "Host: example.com\r \n \
270+ Content-Type: text/html; charset=utf-8\r \n \
271+ Content-Length: 11\r \n \r \n \
272+ hello world";
273+ assert_eq ! ( result, verify) ;
274+ }
275+
276+ #[ test]
277+ fn test_decode_init_no_enc_extra_body ( ) {
278+ let headers = "Host: example.com\r \n \
279+ Content-Type: text/html; charset=utf-8\r \n \
280+ Content-Length: 11\r \n \r \n ";
281+ let mut tm = TestMessage :: build (
282+ headers. into ( ) ,
283+ Body :: Raw ( INPUT . into ( ) ) ,
284+ Some ( INPUT . into ( ) ) ,
285+ ) ;
286+
287+ let mut buf = BytesMut :: new ( ) ;
288+ let mut state = DecodeState :: init ( & mut tm, & mut buf) ;
289+ state = state. try_next ( ) . unwrap ( ) ;
290+ assert ! ( matches!( state, DecodeState :: UpdateContentLength ( _) ) ) ;
258291 state = state. try_next ( ) . unwrap ( ) ;
259292 assert ! ( matches!( state, DecodeState :: End ) ) ;
293+ let result = tm. into_bytes ( ) ;
294+ let verify = "Host: example.com\r \n \
295+ Content-Type: text/html; charset=utf-8\r \n \
296+ Content-Length: 22\r \n \r \n \
297+ hello worldhello world";
298+ assert_eq ! ( result, verify) ;
260299 }
261300}
0 commit comments