Skip to content

Commit

Permalink
Merge branch 'release/0.7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius committed May 18, 2023
2 parents c7e6056 + 59106e4 commit f40d289
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
5 changes: 4 additions & 1 deletion docs/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -810,14 +811,16 @@ 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"

``` bash
export RUSTUS_HOOKS_HTTP_URLS="https://httpbin.org/post"
export RUSTUS_HOOKS_HTTP_PROXY_HEADERS="Authorization"
export RUSTUS_HTTP_HOOK_TIMEOUT="1"

rustus
```
Expand Down
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ pub struct NotificationsOptions {
#[arg(long, env = "RUSTUS_HOOKS_HTTP_URLS", use_value_delimiter = true)]
pub hooks_http_urls: Vec<String>,

/// Timeout for all HTTP requests in seconds.
#[arg(long, env = "RUSTUS_HTTP_HOOK_TIMEOUT")]
pub http_hook_timeout: Option<u64>,

// List of headers to forward from client.
#[arg(
long,
Expand Down
14 changes: 8 additions & 6 deletions src/notifiers/http_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ pub struct HttpNotifier {
urls: Vec<String>,
client: Client,
forward_headers: Vec<String>,
timeout_secs: u64,
}

impl HttpNotifier {
pub fn new(urls: Vec<String>, forward_headers: Vec<String>) -> Self {
pub fn new(urls: Vec<String>, forward_headers: Vec<String>, timeout_secs: Option<u64>) -> Self {
let client = Client::new();
Self {
urls,
client,
forward_headers,
timeout_secs: timeout_secs.unwrap_or(2),
}
}
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/notifiers/models/notification_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl NotificationManager {
.notification_opts
.hooks_http_proxy_headers
.clone(),
rustus_config.notification_opts.http_hook_timeout,
)));
}
#[cfg(feature = "amqp_notifier")]
Expand Down

0 comments on commit f40d289

Please sign in to comment.