31
31
//! not used by Rocket itself but can be used by external libraries. The
32
32
//! standard configuration parameters are:
33
33
//!
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 }` |
46
48
//!
47
49
//! ### Rocket.toml
48
50
//!
64
66
//! port = 8000
65
67
//! workers = [number_of_cpus * 2]
66
68
//! keep_alive = 5
69
+ //! read_timeout = 5
70
+ //! write_timeout = 5
67
71
//! log = "normal"
68
72
//! secret_key = [randomly generated at launch]
69
73
//! limits = { forms = 32768 }
73
77
//! port = 8000
74
78
//! workers = [number_of_cpus * 2]
75
79
//! keep_alive = 5
80
+ //! read_timeout = 5
81
+ //! write_timeout = 5
76
82
//! log = "normal"
77
83
//! secret_key = [randomly generated at launch]
78
84
//! limits = { forms = 32768 }
82
88
//! port = 8000
83
89
//! workers = [number_of_cpus * 2]
84
90
//! keep_alive = 5
91
+ //! read_timeout = 5
92
+ //! write_timeout = 5
85
93
//! log = "critical"
86
94
//! secret_key = [randomly generated at launch]
87
95
//! limits = { forms = 32768 }
@@ -579,6 +587,8 @@ mod test {
579
587
workers = 21
580
588
log = "critical"
581
589
keep_alive = 0
590
+ read_timeout = 1
591
+ write_timeout = 0
582
592
secret_key = "8Xui8SN4mI+7egV/9dlfYYLGQJeEx4+DwmSQLwDVXJg="
583
593
template_dir = "mine"
584
594
json = true
@@ -591,6 +601,8 @@ mod test {
591
601
. workers ( 21 )
592
602
. log_level ( LoggingLevel :: Critical )
593
603
. keep_alive ( 0 )
604
+ . read_timeout ( 1 )
605
+ . write_timeout ( 0 )
594
606
. secret_key ( "8Xui8SN4mI+7egV/9dlfYYLGQJeEx4+DwmSQLwDVXJg=" )
595
607
. extra ( "template_dir" , "mine" )
596
608
. extra ( "json" , true )
@@ -866,7 +878,7 @@ mod test {
866
878
}
867
879
868
880
#[ test]
869
- fn test_good_keep_alives ( ) {
881
+ fn test_good_keep_alives_and_timeouts ( ) {
870
882
// Take the lock so changing the environment doesn't cause races.
871
883
let _env_lock = ENV_LOCK . lock ( ) . unwrap ( ) ;
872
884
env:: set_var ( CONFIG_ENV , "stage" ) ;
@@ -898,10 +910,24 @@ mod test {
898
910
"# . to_string( ) , TEST_CONFIG_FILENAME ) , {
899
911
default_config( Staging ) . keep_alive( 0 )
900
912
} ) ;
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
+ } ) ;
901
927
}
902
928
903
929
#[ test]
904
- fn test_bad_keep_alives ( ) {
930
+ fn test_bad_keep_alives_and_timeouts ( ) {
905
931
// Take the lock so changing the environment doesn't cause races.
906
932
let _env_lock = ENV_LOCK . lock ( ) . unwrap ( ) ;
907
933
env:: remove_var ( CONFIG_ENV ) ;
@@ -925,6 +951,16 @@ mod test {
925
951
[dev]
926
952
keep_alive = 4294967296
927
953
"# . 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( ) ) ;
928
964
}
929
965
930
966
#[ test]
0 commit comments