Skip to content
Merged
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
8 changes: 8 additions & 0 deletions crates/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
15 changes: 10 additions & 5 deletions crates/fastly/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -61,11 +64,6 @@ async fn route_request(
integration_registry: &IntegrationRegistry,
req: Request,
) -> Result<Response, Error> {
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);
}
Expand Down Expand Up @@ -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);
}
Expand Down