@@ -489,6 +489,73 @@ do_idle_timeout_recv_loop(Ref, Pid, ConnPid, StreamRef, ExpectCompletion) ->
489489 error (timeout )
490490 end .
491491
492+ max_authorization_header_value_length (Config ) ->
493+ doc (" Confirm the max_authorization_header_value_length option "
494+ " correctly limits the length of authorization header values." ),
495+ {ok , _ } = cowboy :start_clear (? FUNCTION_NAME , [{port , 0 }], #{
496+ env => #{dispatch => init_dispatch (Config )},
497+ max_authorization_header_value_length => 2048
498+ }),
499+ Port = ranch :get_port (? FUNCTION_NAME ),
500+ try
501+ do_max_header_value_length (Config , Port ,
502+ <<" authorization" >>, 2048 ),
503+ % % Confirm that other headers still use the default limit.
504+ do_max_header_value_length (Config , Port ,
505+ <<" my-header" >>, 4096 )
506+ after
507+ cowboy :stop_listener (? FUNCTION_NAME )
508+ end .
509+
510+ max_cookie_header_value_length (Config ) ->
511+ doc (" Confirm the max_cookie_header_value_length option "
512+ " correctly limits the length of cookie header values." ),
513+ {ok , _ } = cowboy :start_clear (? FUNCTION_NAME , [{port , 0 }], #{
514+ env => #{dispatch => init_dispatch (Config )},
515+ max_cookie_header_value_length => 2048
516+ }),
517+ Port = ranch :get_port (? FUNCTION_NAME ),
518+ try
519+ do_max_header_value_length (Config , Port ,
520+ <<" cookie" >>, 2048 ),
521+ % % Confirm that other headers still use the default limit.
522+ do_max_header_value_length (Config , Port ,
523+ <<" my-header" >>, 4096 )
524+ after
525+ cowboy :stop_listener (? FUNCTION_NAME )
526+ end .
527+
528+ max_header_value_length (Config ) ->
529+ doc (" Confirm the max_header_value_length option "
530+ " correctly limits the length of header values." ),
531+ {ok , _ } = cowboy :start_clear (? FUNCTION_NAME , [{port , 0 }], #{
532+ env => #{dispatch => init_dispatch (Config )},
533+ max_header_value_length => 2048
534+ }),
535+ Port = ranch :get_port (? FUNCTION_NAME ),
536+ try
537+ do_max_header_value_length (Config , Port ,
538+ <<" my-header" >>, 2048 )
539+ after
540+ cowboy :stop_listener (? FUNCTION_NAME )
541+ end .
542+
543+ max_header_value_length_default (Config ) ->
544+ doc (" Confirm the max_header_value_length option "
545+ " correctly limits the length of header values." ),
546+ do_max_header_value_length (Config , config (port , Config ),
547+ <<" my-header" >>, 4096 ).
548+
549+ do_max_header_value_length (Config , Port , Name , MaxLen ) ->
550+ ConnPid = gun_open ([{type , tcp }, {protocol , http }, {port , Port }|Config ]),
551+ {ok , http } = gun :await_up (ConnPid ),
552+ StreamRef1 = gun :get (ConnPid , " /" , #{Name => lists :duplicate (MaxLen , $a )}),
553+ {response , nofin , 200 , _ } = gun :await (ConnPid , StreamRef1 ),
554+ % % We * 2 because this is a soft limit.
555+ StreamRef2 = gun :get (ConnPid , " /" , #{Name => lists :duplicate (MaxLen * 2 , $a )}),
556+ {response , fin , 431 , _ } = gun :await (ConnPid , StreamRef2 ),
557+ gun :close (ConnPid ).
558+
492559persistent_term_router (Config ) ->
493560 doc (" The router can retrieve the routes from persistent_term storage." ),
494561 case erlang :function_exported (persistent_term , get , 1 ) of
0 commit comments