@@ -6,13 +6,21 @@ use url::Url;
66pub struct RetrackConfig {
77 /// The URL to access the Retrack service.
88 pub host : Url ,
9+ /// Maximum allowed JSON body size (in bytes) for the Retrack webhook route.
10+ #[ serde( default = "default_max_webhook_body_size" ) ]
11+ pub max_webhook_body_size : usize ,
12+ }
13+
14+ fn default_max_webhook_body_size ( ) -> usize {
15+ 10 * 1024 * 1024
916}
1017
1118impl Default for RetrackConfig {
1219 fn default ( ) -> Self {
1320 Self {
1421 host : Url :: parse ( "http://localhost:7676" )
1522 . expect ( "Cannot parse Retrack host parameter." ) ,
23+ max_webhook_body_size : default_max_webhook_body_size ( ) ,
1624 }
1725 }
1826}
@@ -43,6 +51,7 @@ mod tests {
4351 query: None,
4452 fragment: None,
4553 },
54+ max_webhook_body_size: 10485760,
4655 }
4756 "### ) ;
4857 }
@@ -59,6 +68,25 @@ mod tests {
5968 config,
6069 RetrackConfig {
6170 host: url:: Url :: parse( "http://localhost:8686" ) . unwrap( ) ,
71+ max_webhook_body_size: 10 * 1024 * 1024 ,
72+ }
73+ ) ;
74+ }
75+
76+ #[ test]
77+ fn deserialization_with_custom_body_size ( ) {
78+ let config: RetrackConfig = toml:: from_str (
79+ r#"
80+ host = 'http://localhost:8686/'
81+ max_webhook_body_size = 52428800
82+ "# ,
83+ )
84+ . unwrap ( ) ;
85+ assert_eq ! (
86+ config,
87+ RetrackConfig {
88+ host: url:: Url :: parse( "http://localhost:8686" ) . unwrap( ) ,
89+ max_webhook_body_size: 50 * 1024 * 1024 ,
6290 }
6391 ) ;
6492 }
0 commit comments