diff --git a/Cargo.lock b/Cargo.lock index ad7fbae..566fe15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3164,7 +3164,7 @@ dependencies = [ [[package]] name = "rustus" -version = "0.7.1" +version = "0.7.2" dependencies = [ "actix-cors", "actix-files", diff --git a/Cargo.toml b/Cargo.toml index 20cf736..c1bf68d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustus" -version = "0.7.1" +version = "0.7.2" edition = "2021" description = "TUS protocol implementation written in Rust." keywords = ["tus", "server", "actix-web"] diff --git a/docs/hooks.md b/docs/hooks.md index 8bc552b..b55f534 100644 --- a/docs/hooks.md +++ b/docs/hooks.md @@ -802,6 +802,7 @@ Configuration parameters: * `--hooks-http-proxy-headers` - list of headers to proxy (separated by commas) to listener's endpoint; * `--hooks-http-urls` - list of absolute urls to send request to (separated by commas). +* `--http-hook-timeout` - Timeout for all http requests in seconds. By default it's 2 seconds. !!! note Hook names are passed as header called `Hook-Name`. @@ -810,7 +811,8 @@ Configuration parameters: ``` bash rustus --hooks-http-urls "https://httpbin.org/post" \ - --hooks-http-proxy-headers "Authorization" + --hooks-http-proxy-headers "Authorization" \ + --http-hook-timeout 1 ``` === "ENV" @@ -818,6 +820,7 @@ Configuration parameters: ``` bash export RUSTUS_HOOKS_HTTP_URLS="https://httpbin.org/post" export RUSTUS_HOOKS_HTTP_PROXY_HEADERS="Authorization" + export RUSTUS_HTTP_HOOK_TIMEOUT="1" rustus ``` diff --git a/src/config.rs b/src/config.rs index 99ae95b..78a997f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -267,6 +267,10 @@ pub struct NotificationsOptions { #[arg(long, env = "RUSTUS_HOOKS_HTTP_URLS", use_value_delimiter = true)] pub hooks_http_urls: Vec, + /// Timeout for all HTTP requests in seconds. + #[arg(long, env = "RUSTUS_HTTP_HOOK_TIMEOUT")] + pub http_hook_timeout: Option, + // List of headers to forward from client. #[arg( long, diff --git a/src/notifiers/http_notifier.rs b/src/notifiers/http_notifier.rs index a5c861d..06aaed8 100644 --- a/src/notifiers/http_notifier.rs +++ b/src/notifiers/http_notifier.rs @@ -13,15 +13,17 @@ pub struct HttpNotifier { urls: Vec, client: Client, forward_headers: Vec, + timeout_secs: u64, } impl HttpNotifier { - pub fn new(urls: Vec, forward_headers: Vec) -> Self { + pub fn new(urls: Vec, forward_headers: Vec, timeout_secs: Option) -> Self { let client = Client::new(); Self { urls, client, forward_headers, + timeout_secs: timeout_secs.unwrap_or(2), } } } @@ -49,7 +51,7 @@ impl Notifier for HttpNotifier { .header("Idempotency-Key", idempotency_key.as_str()) .header("Hook-Name", hook.to_string()) .header("Content-Type", "application/json") - .timeout(Duration::from_secs(2)); + .timeout(Duration::from_secs(self.timeout_secs)); for item in &self.forward_headers { if let Some(value) = header_map.get(item.as_str()) { request = request.header(item.as_str(), value.as_bytes()); @@ -94,7 +96,7 @@ mod tests { ); let hook_url = server.url_str("/hook"); - let notifier = HttpNotifier::new(vec![hook_url], vec![]); + let notifier = HttpNotifier::new(vec![hook_url], vec![], None); notifier .send_message("test_message".into(), Hook::PostCreate, &HeaderMap::new()) .await @@ -115,7 +117,7 @@ mod tests { ); let hook_url = server.url_str("/hook"); - let notifier = HttpNotifier::new(vec![hook_url], vec![]); + let notifier = HttpNotifier::new(vec![hook_url], vec![], None); let result = notifier .send_message("test_message".into(), Hook::PostCreate, &HeaderMap::new()) .await; @@ -133,7 +135,7 @@ mod tests { ); let hook_url = server.url_str("/hook"); - let notifier = HttpNotifier::new(vec![hook_url], vec![]); + let notifier = HttpNotifier::new(vec![hook_url], vec![], None); let result = notifier .send_message("test_message".into(), Hook::PostCreate, &HeaderMap::new()) .await; @@ -151,7 +153,7 @@ mod tests { .respond_with(httptest::responders::status_code(200)), ); let hook_url = server.url_str("/hook"); - let notifier = HttpNotifier::new(vec![hook_url], vec!["X-TEST-HEADER".into()]); + let notifier = HttpNotifier::new(vec![hook_url], vec!["X-TEST-HEADER".into()], None); let mut header_map = HeaderMap::new(); header_map.insert( HeaderName::from_str("X-TEST-HEADER").unwrap(), diff --git a/src/notifiers/models/notification_manager.rs b/src/notifiers/models/notification_manager.rs index c9f449c..923adc3 100644 --- a/src/notifiers/models/notification_manager.rs +++ b/src/notifiers/models/notification_manager.rs @@ -43,6 +43,7 @@ impl NotificationManager { .notification_opts .hooks_http_proxy_headers .clone(), + rustus_config.notification_opts.http_hook_timeout, ))); } #[cfg(feature = "amqp_notifier")]