@@ -185,13 +185,15 @@ impl Decoder {
185185 * state = ready ! ( state. step(
186186 cx,
187187 body,
188- chunk_len,
189- extensions_cnt,
190- & mut buf,
191- trailers_buf,
192- trailers_cnt,
193- h1_max_headers,
194- h1_max_header_size
188+ StepArgs {
189+ chunk_size: chunk_len,
190+ extensions_cnt,
191+ chunk_buf: & mut buf,
192+ trailers_buf,
193+ trailers_cnt,
194+ max_headers_cnt: h1_max_headers,
195+ max_headers_bytes: h1_max_header_size,
196+ }
195197 ) ) ?;
196198 if * state == ChunkedState :: End {
197199 trace ! ( "end of chunked" ) ;
@@ -291,6 +293,16 @@ macro_rules! put_u8 {
291293 } ;
292294}
293295
296+ struct StepArgs < ' a > {
297+ chunk_size : & ' a mut u64 ,
298+ chunk_buf : & ' a mut Option < Bytes > ,
299+ extensions_cnt : & ' a mut u64 ,
300+ trailers_buf : & ' a mut Option < BytesMut > ,
301+ trailers_cnt : & ' a mut usize ,
302+ max_headers_cnt : usize ,
303+ max_headers_bytes : usize ,
304+ }
305+
294306impl ChunkedState {
295307 fn new ( ) -> ChunkedState {
296308 ChunkedState :: Start
@@ -299,35 +311,37 @@ impl ChunkedState {
299311 & self ,
300312 cx : & mut Context < ' _ > ,
301313 body : & mut R ,
302- size : & mut u64 ,
303- extensions_cnt : & mut u64 ,
304- buf : & mut Option < Bytes > ,
305- trailers_buf : & mut Option < BytesMut > ,
306- trailers_cnt : & mut usize ,
307- h1_max_headers : usize ,
308- h1_max_header_size : usize ,
314+ StepArgs {
315+ chunk_size,
316+ chunk_buf,
317+ extensions_cnt,
318+ trailers_buf,
319+ trailers_cnt,
320+ max_headers_cnt,
321+ max_headers_bytes,
322+ } : StepArgs < ' _ > ,
309323 ) -> Poll < Result < ChunkedState , io:: Error > > {
310324 use self :: ChunkedState :: * ;
311325 match * self {
312- Start => ChunkedState :: read_start ( cx, body, size ) ,
313- Size => ChunkedState :: read_size ( cx, body, size ) ,
326+ Start => ChunkedState :: read_start ( cx, body, chunk_size ) ,
327+ Size => ChunkedState :: read_size ( cx, body, chunk_size ) ,
314328 SizeLws => ChunkedState :: read_size_lws ( cx, body) ,
315329 Extension => ChunkedState :: read_extension ( cx, body, extensions_cnt) ,
316- SizeLf => ChunkedState :: read_size_lf ( cx, body, * size ) ,
317- Body => ChunkedState :: read_body ( cx, body, size , buf ) ,
330+ SizeLf => ChunkedState :: read_size_lf ( cx, body, * chunk_size ) ,
331+ Body => ChunkedState :: read_body ( cx, body, chunk_size , chunk_buf ) ,
318332 BodyCr => ChunkedState :: read_body_cr ( cx, body) ,
319333 BodyLf => ChunkedState :: read_body_lf ( cx, body) ,
320- Trailer => ChunkedState :: read_trailer ( cx, body, trailers_buf, h1_max_header_size ) ,
334+ Trailer => ChunkedState :: read_trailer ( cx, body, trailers_buf, max_headers_bytes ) ,
321335 TrailerLf => ChunkedState :: read_trailer_lf (
322336 cx,
323337 body,
324338 trailers_buf,
325339 trailers_cnt,
326- h1_max_headers ,
327- h1_max_header_size ,
340+ max_headers_cnt ,
341+ max_headers_bytes ,
328342 ) ,
329- EndCr => ChunkedState :: read_end_cr ( cx, body, trailers_buf, h1_max_header_size ) ,
330- EndLf => ChunkedState :: read_end_lf ( cx, body, trailers_buf, h1_max_header_size ) ,
343+ EndCr => ChunkedState :: read_end_cr ( cx, body, trailers_buf, max_headers_bytes ) ,
344+ EndLf => ChunkedState :: read_end_lf ( cx, body, trailers_buf, max_headers_bytes ) ,
331345 End => Poll :: Ready ( Ok ( ChunkedState :: End ) ) ,
332346 }
333347 }
@@ -750,13 +764,15 @@ mod tests {
750764 state. step (
751765 cx,
752766 rdr,
753- & mut size,
754- & mut ext_cnt,
755- & mut None ,
756- & mut None ,
757- & mut trailers_cnt,
758- DEFAULT_MAX_HEADERS ,
759- TRAILER_LIMIT ,
767+ StepArgs {
768+ chunk_size : & mut size,
769+ extensions_cnt : & mut ext_cnt,
770+ chunk_buf : & mut None ,
771+ trailers_buf : & mut None ,
772+ trailers_cnt : & mut trailers_cnt,
773+ max_headers_cnt : DEFAULT_MAX_HEADERS ,
774+ max_headers_bytes : TRAILER_LIMIT ,
775+ } ,
760776 )
761777 } )
762778 . await ;
@@ -780,13 +796,15 @@ mod tests {
780796 state. step (
781797 cx,
782798 rdr,
783- & mut size,
784- & mut ext_cnt,
785- & mut None ,
786- & mut None ,
787- & mut trailers_cnt,
788- DEFAULT_MAX_HEADERS ,
789- TRAILER_LIMIT ,
799+ StepArgs {
800+ chunk_size : & mut size,
801+ extensions_cnt : & mut ext_cnt,
802+ chunk_buf : & mut None ,
803+ trailers_buf : & mut None ,
804+ trailers_cnt : & mut trailers_cnt,
805+ max_headers_cnt : DEFAULT_MAX_HEADERS ,
806+ max_headers_bytes : TRAILER_LIMIT ,
807+ } ,
790808 )
791809 } )
792810 . await ;
0 commit comments