expose traceresponse header in CORS (#644)

The
[traceresponse](https://w3c.github.io/trace-context/#traceresponse-header)
header needs to be exposed over CORS request's so that clients can
retrieve for further processing. We emit this response header to
represent tracecontext.

ref
[this](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers)
for more info

V3_GIT_ORIGIN_REV_ID: 7944c764343b201b37a635acfb927910202784ad
This commit is contained in:
Rakesh Emmadi 2024-05-30 19:57:23 +05:30 committed by hasura-bot
parent 835668b03c
commit f04bdc59d7

View File

@ -1,3 +1,4 @@
use axum::http::header::HeaderName;
use reqwest::Method; use reqwest::Method;
use std::time::Duration; use std::time::Duration;
use tower_http::cors; use tower_http::cors;
@ -18,13 +19,15 @@ pub fn build_cors_layer(cors_allow_origin: &[String]) -> cors::CorsLayer {
}) })
}) })
}; };
// Allow traceresponse to be retrievable on CORS
let trace_response_header_name = HeaderName::from_static("traceresponse");
cors::CorsLayer::new() cors::CorsLayer::new()
.max_age(Duration::from_secs(24 * 60 * 60)) // 24 hours .max_age(Duration::from_secs(24 * 60 * 60)) // 24 hours
.allow_headers(cors::AllowHeaders::mirror_request()) .allow_headers(cors::AllowHeaders::mirror_request())
.allow_origin(cors_allow_origin) .allow_origin(cors_allow_origin)
.allow_credentials(true) .allow_credentials(true)
.allow_methods(vec![Method::GET, Method::POST, Method::OPTIONS]) .allow_methods(vec![Method::GET, Method::POST, Method::OPTIONS])
.expose_headers([trace_response_header_name])
} }
#[cfg(test)] #[cfg(test)]