From af64de041bad3670b38f1ff63aaaaea8ecc143a2 Mon Sep 17 00:00:00 2001 From: FabianLars Date: Wed, 5 Nov 2025 13:43:00 +0100 Subject: [PATCH] feat: add Referer to HeaderConfig --- crates/tauri-cli/config.schema.json | 11 +++++++++++ .../tauri-schema-generator/schemas/config.schema.json | 11 +++++++++++ crates/tauri-utils/src/config.rs | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/crates/tauri-cli/config.schema.json b/crates/tauri-cli/config.schema.json index b2953239f..29725bc10 100644 --- a/crates/tauri-cli/config.schema.json +++ b/crates/tauri-cli/config.schema.json @@ -1767,6 +1767,17 @@ } ] }, + "Referer": { + "description": "TODO: docs", + "anyOf": [ + { + "$ref": "#/definitions/HeaderSource" + }, + { + "type": "null" + } + ] + }, "Tauri-Custom-Header": { "description": "A custom header field Tauri-Custom-Header, don't use it.\n Remember to set Access-Control-Expose-Headers accordingly\n\n **NOT INTENDED FOR PRODUCTION USE**", "anyOf": [ diff --git a/crates/tauri-schema-generator/schemas/config.schema.json b/crates/tauri-schema-generator/schemas/config.schema.json index b2953239f..29725bc10 100644 --- a/crates/tauri-schema-generator/schemas/config.schema.json +++ b/crates/tauri-schema-generator/schemas/config.schema.json @@ -1767,6 +1767,17 @@ } ] }, + "Referer": { + "description": "TODO: docs", + "anyOf": [ + { + "$ref": "#/definitions/HeaderSource" + }, + { + "type": "null" + } + ] + }, "Tauri-Custom-Header": { "description": "A custom header field Tauri-Custom-Header, don't use it.\n Remember to set Access-Control-Expose-Headers accordingly\n\n **NOT INTENDED FOR PRODUCTION USE**", "anyOf": [ diff --git a/crates/tauri-utils/src/config.rs b/crates/tauri-utils/src/config.rs index 37c77abff..d17c2611c 100644 --- a/crates/tauri-utils/src/config.rs +++ b/crates/tauri-utils/src/config.rs @@ -2390,6 +2390,11 @@ impl HeaderAddition for Builder { self = self.header("X-Content-Type-Options", value.to_string()); }; + // Add the header X-Content-Type-Options, if we find a value for it + if let Some(value) = &headers.referer { + self = self.header("Referer", value.to_string()); + }; + // Add the header Tauri-Custom-Header, if we find a value for it if let Some(value) = &headers.tauri_custom_header { // Keep in mind to correctly set the Access-Control-Expose-Headers @@ -2543,6 +2548,9 @@ pub struct HeaderConfig { /// See #[serde(rename = "X-Content-Type-Options")] pub x_content_type_options: Option, + /// TODO: docs + #[serde(rename = "Referer")] + pub referer: Option, /// A custom header field Tauri-Custom-Header, don't use it. /// Remember to set Access-Control-Expose-Headers accordingly /// @@ -2567,6 +2575,7 @@ impl HeaderConfig { service_worker_allowed: None, timing_allow_origin: None, x_content_type_options: None, + referer: None, tauri_custom_header: None, } } @@ -3920,6 +3929,7 @@ mod build { let service_worker_allowed = opt_lit(self.service_worker_allowed.as_ref()); let timing_allow_origin = opt_lit(self.timing_allow_origin.as_ref()); let x_content_type_options = opt_lit(self.x_content_type_options.as_ref()); + let referer = opt_lit(self.referer.as_ref()); let tauri_custom_header = opt_lit(self.tauri_custom_header.as_ref()); literal_struct!( @@ -3937,6 +3947,7 @@ mod build { service_worker_allowed, timing_allow_origin, x_content_type_options, + referer, tauri_custom_header ); }