From 4eeec0b773e03c11742e63e06e3c0021c1e829a0 Mon Sep 17 00:00:00 2001 From: Dmitrii Fedorov Date: Wed, 7 May 2025 17:44:05 -0700 Subject: [PATCH] feat(envoy): Allow to pass arbitrary http headers to upstream calls --- relay-config/src/config.rs | 11 +++++++++++ relay-server/src/services/upstream.rs | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/relay-config/src/config.rs b/relay-config/src/config.rs index 2637f591ba..fef39aec5f 100644 --- a/relay-config/src/config.rs +++ b/relay-config/src/config.rs @@ -854,6 +854,11 @@ pub struct Http { /// /// This option does not have any effect on processing mode. pub global_metrics: bool, + /// Additional HTTP headers to send with every request to the upstream. + /// + /// These headers are added to every request made to the upstream. They can be used to + /// configure custom authentication, routing, or other HTTP headers required by the upstream. + additional_headers: HashMap, } impl Default for Http { @@ -869,6 +874,7 @@ impl Default for Http { project_failure_interval: default_project_failure_interval(), encoding: HttpEncoding::Zstd, global_metrics: false, + additional_headers: HashMap::new(), } } } @@ -1898,6 +1904,11 @@ impl Config { self.values.http.host_header.as_deref() } + /// Returns additional HTTP headers to send with every request to the upstream. + pub fn http_additional_headers(&self) -> &HashMap { + &self.values.http.additional_headers + } + /// Returns the listen address. pub fn listen_addr(&self) -> SocketAddr { (self.values.relay.host, self.values.relay.port).into() diff --git a/relay-server/src/services/upstream.rs b/relay-server/src/services/upstream.rs index dce270d6eb..47b9770845 100644 --- a/relay-server/src/services/upstream.rs +++ b/relay-server/src/services/upstream.rs @@ -771,9 +771,13 @@ impl SharedClient { .config .http_host_header() .unwrap_or_else(|| self.config.upstream_descriptor().host()); + let additional_headers = self.config.http_additional_headers(); let mut builder = RequestBuilder::reqwest(self.reqwest.request(request.method(), url)); builder.header("Host", host_header.as_bytes()); + for (key, value) in additional_headers { + builder.header(key, value); + } if request.set_relay_id() { if let Some(credentials) = self.config.credentials() {