relay_server/extractors/
content_type.rs1use std::convert::Infallible;
2use std::fmt;
3
4use axum::extract::FromRequestParts;
5use axum::http::header;
6use axum::http::request::Parts;
7
8#[derive(Clone, Debug, PartialEq, Eq)]
9pub struct RawContentType(String);
10
11impl fmt::Display for RawContentType {
12 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13 self.0.fmt(f)
14 }
15}
16
17impl AsRef<str> for RawContentType {
18 fn as_ref(&self) -> &str {
19 &self.0
20 }
21}
22
23impl<S: Send + Sync> FromRequestParts<S> for RawContentType {
24 type Rejection = Infallible;
25
26 async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
27 let mime = parts
28 .headers
29 .get(header::CONTENT_TYPE)
30 .and_then(|v| v.to_str().ok())
31 .unwrap_or("")
32 .to_owned();
33
34 Ok(Self(mime))
35 }
36}