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 std::fmt::Display for DownstreamService {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 f.write_str(self.0.as_deref().unwrap_or("unknown"))
28 }
29}
30
31impl<S: Send + Sync> FromRequestParts<S> for DownstreamService {
32 type Rejection = std::convert::Infallible;
33
34 async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
35 let service = parts
36 .headers
37 .get(HEADER_SERVICE)
38 .and_then(|v| v.to_str().ok())
39 .map(|s| s.to_string());
40
41 if let Some(ref service) = service {
42 sentry::configure_scope(|s| {
43 s.set_tag("downstream_service", service);
44 });
45 }
46
47 Ok(DownstreamService(service))
48 }
49}