Skip to content

feat(envoy): Allow to pass arbitrary http headers to upstream calls #4713

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions relay-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>,
}

impl Default for Http {
Expand All @@ -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(),
}
}
}
Expand Down Expand Up @@ -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<String, String> {
&self.values.http.additional_headers
}

/// Returns the listen address.
pub fn listen_addr(&self) -> SocketAddr {
(self.values.relay.host, self.values.relay.port).into()
Expand Down
4 changes: 4 additions & 0 deletions relay-server/src/services/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading