objectstore_server/extractors/
downstream_service.rs1use axum::extract::FromRequestParts;
4use axum::http::request::Parts;
5
6const HEADER_SERVICE: &str = "x-downstream-service";
9
10#[derive(Debug, Clone)]
16pub struct DownstreamService(pub Option<String>);
17
18impl DownstreamService {
19 pub fn as_str(&self) -> Option<&str> {
21 self.0.as_deref()
22 }
23}
24
25impl<S: Send + Sync> FromRequestParts<S> for DownstreamService {
26 type Rejection = std::convert::Infallible;
27
28 async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
29 let service = parts
30 .headers
31 .get(HEADER_SERVICE)
32 .and_then(|v| v.to_str().ok())
33 .map(|s| s.to_string());
34
35 if let Some(ref service) = service {
36 sentry::configure_scope(|s| {
37 s.set_tag("downstream_service", service);
38 });
39 }
40
41 Ok(DownstreamService(service))
42 }
43}