diff --git a/crates/common/src/constants.rs b/crates/common/src/constants.rs index 4ccb77f9..ea51df86 100644 --- a/crates/common/src/constants.rs +++ b/crates/common/src/constants.rs @@ -19,6 +19,14 @@ pub const HEADER_X_REQUEST_ID: HeaderName = HeaderName::from_static("x-request-i pub const HEADER_X_COMPRESS_HINT: HeaderName = HeaderName::from_static("x-compress-hint"); pub const HEADER_X_DEBUG_FASTLY_POP: HeaderName = HeaderName::from_static("x-debug-fastly-pop"); +// Staging / version identification headers +pub const HEADER_X_TS_VERSION: HeaderName = HeaderName::from_static("x-ts-version"); +pub const HEADER_X_TS_ENV: HeaderName = HeaderName::from_static("x-ts-env"); + +// Fastly environment variables +pub const ENV_FASTLY_SERVICE_VERSION: &str = "FASTLY_SERVICE_VERSION"; +pub const ENV_FASTLY_IS_STAGING: &str = "FASTLY_IS_STAGING"; + // Common standard header names used across modules pub const HEADER_USER_AGENT: HeaderName = HeaderName::from_static("user-agent"); pub const HEADER_ACCEPT: HeaderName = HeaderName::from_static("accept"); diff --git a/crates/fastly/src/main.rs b/crates/fastly/src/main.rs index 0112bd99..33b58f37 100644 --- a/crates/fastly/src/main.rs +++ b/crates/fastly/src/main.rs @@ -6,6 +6,9 @@ use log_fastly::Logger; use trusted_server_common::auction::endpoints::handle_auction; use trusted_server_common::auction::{build_orchestrator, AuctionOrchestrator}; use trusted_server_common::auth::enforce_basic_auth; +use trusted_server_common::constants::{ + ENV_FASTLY_IS_STAGING, ENV_FASTLY_SERVICE_VERSION, HEADER_X_TS_ENV, HEADER_X_TS_VERSION, +}; use trusted_server_common::error::TrustedServerError; use trusted_server_common::integrations::IntegrationRegistry; use trusted_server_common::proxy::{ @@ -61,11 +64,6 @@ async fn route_request( integration_registry: &IntegrationRegistry, req: Request, ) -> Result { - log::info!( - "FASTLY_SERVICE_VERSION: {}", - ::std::env::var("FASTLY_SERVICE_VERSION").unwrap_or_else(|_| String::new()) - ); - if let Some(response) = enforce_basic_auth(settings, &req) { return Ok(response); } @@ -132,6 +130,13 @@ async fn route_request( // Convert any errors to HTTP error responses let mut response = result.unwrap_or_else(|e| to_error_response(&e)); + if let Ok(v) = ::std::env::var(ENV_FASTLY_SERVICE_VERSION) { + response.set_header(HEADER_X_TS_VERSION, v); + } + if ::std::env::var(ENV_FASTLY_IS_STAGING).as_deref() == Ok("1") { + response.set_header(HEADER_X_TS_ENV, "staging"); + } + for (key, value) in &settings.response_headers { response.set_header(key, value); }