use http;
use crate::JsonApiErrorResponse;
pub fn validate_content_type<B>(req: &http::Request<B>) -> Result<(), JsonApiErrorResponse> {
if req.method() == http::Method::POST || req.method() == http::Method::PATCH {
let content_type = req.headers().get(http::header::CONTENT_TYPE);
if content_type.is_none() || content_type.unwrap() != "application/vnd.api+json" {
return Err(crate::bad_request_error(
"Unsupported Media Type",
"Content-Type must be application/vnd.api+json",
));
}
}
Ok(())
}
pub fn set_content_type<B>(res: &mut http::Response<B>) {
res.headers_mut().insert(
http::header::CONTENT_TYPE,
"application/vnd.api+json".parse().unwrap(),
);
}