relay_server/extractors/
received_at.rs1use std::convert::Infallible;
2
3use axum::Extension;
4use axum::extract::FromRequestParts;
5use axum::http::request::Parts;
6use chrono::{DateTime, Utc};
7
8#[derive(Clone, Copy, Debug)]
10pub struct ReceivedAt(pub DateTime<Utc>);
11
12impl ReceivedAt {
13 pub fn now() -> Self {
14 Self(Utc::now())
15 }
16}
17
18impl<S> FromRequestParts<S> for ReceivedAt
19where
20 S: Send + Sync,
21{
22 type Rejection = Infallible;
23
24 async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
25 let Extension(start_time) = Extension::from_request_parts(parts, state)
26 .await
27 .expect("ReceivedAt middleware is not configured");
28
29 Ok(start_time)
30 }
31}