Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

757: Add new options for prefix of whitelabel headers (whitelabel_hea… #759

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/svix-server/config.default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ cache_type = "memory"
# If true, headers are prefixed with `Webhook-`, otherwise with `Svix-` (default).
whitelabel_headers = false

# If value is configured, headers are prefixed with custom configured prefix value, otherwise with `Webhook-` (default).
whitelabel_header_prefix = "Custom-"

# If true, only allow https endpoints, otherwise also allow http.
endpoint_https_only = false

Expand Down
3 changes: 3 additions & 0 deletions server/svix-server/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ pub struct ConfigurationInner {
/// If true, headers are prefixed with `Webhook-`, otherwise with `Svix-` (default).
pub whitelabel_headers: bool,

/// # If value is configured, headers are prefixed with custom configured prefix value, otherwise with `Webhook-` (default).
pub whitelabel_header_prefix: String,

/// If true, only allow https endpoints, otherwise also allow http.
pub endpoint_https_only: bool,

Expand Down
13 changes: 10 additions & 3 deletions server/svix-server/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ fn generate_msg_headers(
msg_id: &MessageId,
signatures: String,
whitelabel_headers: bool,
whitelabel_header_prefix: String,
configured_headers: Option<&EndpointHeaders>,
_endpoint_url: &str,
) -> HeaderMap {
Expand All @@ -185,9 +186,10 @@ fn generate_msg_headers(
.parse()
.expect("Error parsing message signatures");
if whitelabel_headers {
headers.insert("webhook-id", id);
headers.insert("webhook-timestamp", timestamp);
headers.insert("webhook-signature", signatures_str);
let webhook_prefix = if whitelabel_header_prefix.is_empty() { "webhook-" } else { whitelabel_header_prefix };
headers.insert(format!("{webhook_prefix}id"), id);
headers.insert(format!("{webhook_prefix}timestamp"), timestamp);
headers.insert(format!("{webhook_prefix}signature"), signatures_str);
} else {
headers.insert("svix-id", id);
headers.insert("svix-timestamp", timestamp);
Expand Down Expand Up @@ -272,6 +274,7 @@ async fn dispatch(
&msg_task.msg_id,
signatures,
cfg.whitelabel_headers,
cfg.whitelabel_header_prefix,
endp.headers.as_ref(),
&endp.url,
);
Expand Down Expand Up @@ -735,6 +738,7 @@ mod tests {
// [`generate_msg_headers`] tests
const TIMESTAMP: i64 = 1;
const WHITELABEL_HEADERS: bool = false;
const WHITELABEL_HEADER_PREFIX: &str = "custom-"
const BODY: &str = "{\"test\": \"body\"}";
const ENDPOINT_SIGNING_KEYS: &[&EndpointSecretInternal] = &[];
const ENDPOINT_URL: &str = "http://localhost:8071";
Expand All @@ -758,6 +762,7 @@ mod tests {
&id,
signatures,
WHITELABEL_HEADERS,
WHITELABEL_HEADER_PREFIX,
None,
ENDPOINT_URL,
),
Expand Down Expand Up @@ -791,6 +796,7 @@ mod tests {
&id,
signatures,
WHITELABEL_HEADERS,
WHITELABEL_HEADER_PREFIX,
Some(&EndpointHeaders(headers)),
ENDPOINT_URL,
);
Expand Down Expand Up @@ -826,6 +832,7 @@ mod tests {
&test_message_id,
signatures,
WHITELABEL_HEADERS,
WHITELABEL_HEADER_PREFIX,
None,
ENDPOINT_URL,
);
Expand Down