relay_server/extractors/
received_at.rsuse std::convert::Infallible;
use axum::extract::FromRequestParts;
use axum::http::request::Parts;
use axum::Extension;
use chrono::{DateTime, Utc};
#[derive(Clone, Copy, Debug)]
pub struct ReceivedAt(pub DateTime<Utc>);
impl ReceivedAt {
pub fn now() -> Self {
Self(Utc::now())
}
}
#[axum::async_trait]
impl<S> FromRequestParts<S> for ReceivedAt
where
S: Send + Sync,
{
type Rejection = Infallible;
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let Extension(start_time) = Extension::from_request_parts(parts, state)
.await
.expect("ReceivedAt middleware is not configured");
Ok(start_time)
}
}