Skip to content

Commit 8e70d34

Browse files
committed
fix(web-scraping): make Retrack webhook payload size configurable and bump default from 2MB to 10MB
1 parent 70c3a54 commit 8e70d34

4 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ mod tests {
400400
query: None,
401401
fragment: None,
402402
},
403+
max_webhook_body_size: 10485760,
403404
},
404405
platform: PlatformConfig {
405406
max_import_file_size: 10485760,

src/config/raw_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ mod tests {
236236
237237
[retrack]
238238
host = 'http://localhost:7676/'
239+
max_webhook_body_size = 10485760
239240
240241
[platform]
241242
max_import_file_size = 10485760
@@ -672,6 +673,7 @@ mod tests {
672673
query: None,
673674
fragment: None,
674675
},
676+
max_webhook_body_size: 10485760,
675677
},
676678
platform: PlatformConfig {
677679
max_import_file_size: 10485760,

src/config/retrack_config.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ use url::Url;
66
pub 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

1118
impl 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
}

src/server.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub async fn run(config: Config, http_port: u16) -> Result<(), anyhow::Error> {
109109
JsRuntime::init_platform();
110110

111111
let max_responder_body_size = config.utils.max_responder_body_size;
112+
let max_retrack_webhook_body_size = config.retrack.max_webhook_body_size;
112113
let max_import_file_size = config.platform.max_import_file_size;
113114
let session_cookie_name = config.security.session_cookie_name.clone();
114115
let state = web::Data::new(AppState::new(config, api.clone()));
@@ -249,7 +250,14 @@ pub async fn run(config: Config, http_port: u16) -> Result<(), anyhow::Error> {
249250
web::scope("/api")
250251
.service(
251252
web::scope("/webhooks")
252-
.route("/retrack", web::post().to(handlers::webhooks_retrack))
253+
.service(
254+
web::scope("/retrack")
255+
.app_data(
256+
web::JsonConfig::default()
257+
.limit(max_retrack_webhook_body_size),
258+
)
259+
.route("", web::post().to(handlers::webhooks_retrack)),
260+
)
253261
.service(
254262
web::scope("")
255263
.app_data(

0 commit comments

Comments
 (0)