3131//! not used by Rocket itself but can be used by external libraries. The
3232//! standard configuration parameters are:
3333//!
34- //! | name | type | description | examples |
35- //! |------------|----------------|-------------------------------------------------------------|----------------------------|
36- //! | address | string | ip address or host to listen on | `"localhost"`, `"1.2.3.4"` |
37- //! | port | integer | port number to listen on | `8000`, `80` |
38- //! | keep_alive | integer | keep-alive timeout in seconds | `0` (disable), `10` |
39- //! | workers | integer | number of concurrent thread workers | `36`, `512` |
40- //! | log | string | max log level: `"off"`, `"normal"`, `"debug"`, `"critical"` | `"off"`, `"normal"` |
41- //! | secret_key | 256-bit base64 | secret key for private cookies | `"8Xui8SI..."` (44 chars) |
42- //! | tls | table | tls config table with two keys (`certs`, `key`) | _see below_ |
43- //! | tls.certs | string | path to certificate chain in PEM format | `"private/cert.pem"` |
44- //! | tls.key | string | path to private key for `tls.certs` in PEM format | `"private/key.pem"` |
45- //! | limits | table | map from data type (string) to data limit (integer: bytes) | `{ forms = 65536 }` |
34+ //! | name | type | description | examples |
35+ //! |------------ |----------------|-------------------------------------------------------------|----------------------------|
36+ //! | address | string | ip address or host to listen on | `"localhost"`, `"1.2.3.4"` |
37+ //! | port | integer | port number to listen on | `8000`, `80` |
38+ //! | keep_alive | integer | keep-alive timeout in seconds | `0` (disable), `10` |
39+ //! | read_timeout | integer | data read timeout in seconds | `0` (disable), `5` |
40+ //! | write_timeout | integer | data write timeout in seconds | `0` (disable), `5` |
41+ //! | workers | integer | number of concurrent thread workers | `36`, `512` |
42+ //! | log | string | max log level: `"off"`, `"normal"`, `"debug"`, `"critical"` | `"off"`, `"normal"` |
43+ //! | secret_key | 256-bit base64 | secret key for private cookies | `"8Xui8SI..."` (44 chars) |
44+ //! | tls | table | tls config table with two keys (`certs`, `key`) | _see below_ |
45+ //! | tls.certs | string | path to certificate chain in PEM format | `"private/cert.pem"` |
46+ //! | tls.key | string | path to private key for `tls.certs` in PEM format | `"private/key.pem"` |
47+ //! | limits | table | map from data type (string) to data limit (integer: bytes) | `{ forms = 65536 }` |
4648//!
4749//! ### Rocket.toml
4850//!
6466//! port = 8000
6567//! workers = [number_of_cpus * 2]
6668//! keep_alive = 5
69+ //! read_timeout = 5
70+ //! write_timeout = 5
6771//! log = "normal"
6872//! secret_key = [randomly generated at launch]
6973//! limits = { forms = 32768 }
7377//! port = 8000
7478//! workers = [number_of_cpus * 2]
7579//! keep_alive = 5
80+ //! read_timeout = 5
81+ //! write_timeout = 5
7682//! log = "normal"
7783//! secret_key = [randomly generated at launch]
7884//! limits = { forms = 32768 }
8288//! port = 8000
8389//! workers = [number_of_cpus * 2]
8490//! keep_alive = 5
91+ //! read_timeout = 5
92+ //! write_timeout = 5
8593//! log = "critical"
8694//! secret_key = [randomly generated at launch]
8795//! limits = { forms = 32768 }
@@ -579,6 +587,8 @@ mod test {
579587 workers = 21
580588 log = "critical"
581589 keep_alive = 0
590+ read_timeout = 1
591+ write_timeout = 0
582592 secret_key = "8Xui8SN4mI+7egV/9dlfYYLGQJeEx4+DwmSQLwDVXJg="
583593 template_dir = "mine"
584594 json = true
@@ -591,6 +601,8 @@ mod test {
591601 . workers ( 21 )
592602 . log_level ( LoggingLevel :: Critical )
593603 . keep_alive ( 0 )
604+ . read_timeout ( 1 )
605+ . write_timeout ( 0 )
594606 . secret_key ( "8Xui8SN4mI+7egV/9dlfYYLGQJeEx4+DwmSQLwDVXJg=" )
595607 . extra ( "template_dir" , "mine" )
596608 . extra ( "json" , true )
@@ -866,7 +878,7 @@ mod test {
866878 }
867879
868880 #[ test]
869- fn test_good_keep_alives ( ) {
881+ fn test_good_keep_alives_and_timeouts ( ) {
870882 // Take the lock so changing the environment doesn't cause races.
871883 let _env_lock = ENV_LOCK . lock ( ) . unwrap ( ) ;
872884 env:: set_var ( CONFIG_ENV , "stage" ) ;
@@ -898,10 +910,24 @@ mod test {
898910 "# . to_string( ) , TEST_CONFIG_FILENAME ) , {
899911 default_config( Staging ) . keep_alive( 0 )
900912 } ) ;
913+
914+ check_config ! ( RocketConfig :: parse( r#"
915+ [stage]
916+ read_timeout = 10
917+ "# . to_string( ) , TEST_CONFIG_FILENAME ) , {
918+ default_config( Staging ) . read_timeout( 10 )
919+ } ) ;
920+
921+ check_config ! ( RocketConfig :: parse( r#"
922+ [stage]
923+ write_timeout = 4
924+ "# . to_string( ) , TEST_CONFIG_FILENAME ) , {
925+ default_config( Staging ) . write_timeout( 4 )
926+ } ) ;
901927 }
902928
903929 #[ test]
904- fn test_bad_keep_alives ( ) {
930+ fn test_bad_keep_alives_and_timeouts ( ) {
905931 // Take the lock so changing the environment doesn't cause races.
906932 let _env_lock = ENV_LOCK . lock ( ) . unwrap ( ) ;
907933 env:: remove_var ( CONFIG_ENV ) ;
@@ -925,6 +951,16 @@ mod test {
925951 [dev]
926952 keep_alive = 4294967296
927953 "# . to_string( ) , TEST_CONFIG_FILENAME ) . is_err( ) ) ;
954+
955+ assert ! ( RocketConfig :: parse( r#"
956+ [dev]
957+ read_timeout = true
958+ "# . to_string( ) , TEST_CONFIG_FILENAME ) . is_err( ) ) ;
959+
960+ assert ! ( RocketConfig :: parse( r#"
961+ [dev]
962+ write_timeout = None
963+ "# . to_string( ) , TEST_CONFIG_FILENAME ) . is_err( ) ) ;
928964 }
929965
930966 #[ test]
0 commit comments