use std::{borrow::Cow, fmt::Display};
use axum::extract::Request;
use tower_http::request_id::{MakeRequestId, RequestId};
use uuid::Uuid;
pub mod file;
pub mod json_schema;
pub mod multipart;
pub mod urlencoded;
#[derive(Debug, Clone)]
pub struct ContentType<'a>(pub Cow<'a, str>);
impl<'a> Display for ContentType<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl<'a> ContentType<'a> {
pub fn new(content_type: impl Into<Cow<'a, str>>) -> Self {
Self(content_type.into())
}
pub fn is_json(&self) -> bool {
self.0.starts_with("application/json")
}
pub fn is_form(&self) -> bool {
self.0.starts_with("application/x-www-form-urlencoded")
}
pub fn is_multipart(&self) -> bool {
self.0.starts_with("multipart/form-data")
}
}
#[derive(Clone, Copy, Default)]
pub struct MakeRequestUuidV7;
impl MakeRequestId for MakeRequestUuidV7 {
fn make_request_id<B>(&mut self, _request: &Request<B>) -> Option<RequestId> {
let request_id = Uuid::now_v7().to_string().parse().unwrap();
Some(RequestId::new(request_id))
}
}