Skip to content

Commit 67251c7

Browse files
authored
Add staging environment identification headers (#326)
1 parent 2954c52 commit 67251c7

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

crates/common/src/constants.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ pub const HEADER_X_REQUEST_ID: HeaderName = HeaderName::from_static("x-request-i
1919
pub const HEADER_X_COMPRESS_HINT: HeaderName = HeaderName::from_static("x-compress-hint");
2020
pub const HEADER_X_DEBUG_FASTLY_POP: HeaderName = HeaderName::from_static("x-debug-fastly-pop");
2121

22+
// Staging / version identification headers
23+
pub const HEADER_X_TS_VERSION: HeaderName = HeaderName::from_static("x-ts-version");
24+
pub const HEADER_X_TS_ENV: HeaderName = HeaderName::from_static("x-ts-env");
25+
26+
// Fastly environment variables
27+
pub const ENV_FASTLY_SERVICE_VERSION: &str = "FASTLY_SERVICE_VERSION";
28+
pub const ENV_FASTLY_IS_STAGING: &str = "FASTLY_IS_STAGING";
29+
2230
// Common standard header names used across modules
2331
pub const HEADER_USER_AGENT: HeaderName = HeaderName::from_static("user-agent");
2432
pub const HEADER_ACCEPT: HeaderName = HeaderName::from_static("accept");

crates/fastly/src/main.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use log_fastly::Logger;
66
use trusted_server_common::auction::endpoints::handle_auction;
77
use trusted_server_common::auction::{build_orchestrator, AuctionOrchestrator};
88
use trusted_server_common::auth::enforce_basic_auth;
9+
use trusted_server_common::constants::{
10+
ENV_FASTLY_IS_STAGING, ENV_FASTLY_SERVICE_VERSION, HEADER_X_TS_ENV, HEADER_X_TS_VERSION,
11+
};
912
use trusted_server_common::error::TrustedServerError;
1013
use trusted_server_common::integrations::IntegrationRegistry;
1114
use trusted_server_common::proxy::{
@@ -61,11 +64,6 @@ async fn route_request(
6164
integration_registry: &IntegrationRegistry,
6265
req: Request,
6366
) -> Result<Response, Error> {
64-
log::info!(
65-
"FASTLY_SERVICE_VERSION: {}",
66-
::std::env::var("FASTLY_SERVICE_VERSION").unwrap_or_else(|_| String::new())
67-
);
68-
6967
if let Some(response) = enforce_basic_auth(settings, &req) {
7068
return Ok(response);
7169
}
@@ -132,6 +130,13 @@ async fn route_request(
132130
// Convert any errors to HTTP error responses
133131
let mut response = result.unwrap_or_else(|e| to_error_response(&e));
134132

133+
if let Ok(v) = ::std::env::var(ENV_FASTLY_SERVICE_VERSION) {
134+
response.set_header(HEADER_X_TS_VERSION, v);
135+
}
136+
if ::std::env::var(ENV_FASTLY_IS_STAGING).as_deref() == Ok("1") {
137+
response.set_header(HEADER_X_TS_ENV, "staging");
138+
}
139+
135140
for (key, value) in &settings.response_headers {
136141
response.set_header(key, value);
137142
}

0 commit comments

Comments
 (0)