use hyper::{
HeaderMap,
header::{CONTENT_TYPE, HeaderValue},
};
use tokio::time;
use std::time::Duration;
pub fn content_type_is_application_json(headers: &HeaderMap<HeaderValue>) -> Option<bool> {
let content_type = headers.get(CONTENT_TYPE)?;
let Ok(content_type) = content_type.to_str() else {
return Some(false);
};
Some(
content_type
.trim_start()
.to_ascii_lowercase()
.starts_with("application/json"),
)
}
pub fn normalize_url_path(url_path: &str, url_path_prefix: Option<&str>) -> String {
let url_path_prefix = match url_path_prefix {
Some(prefix) if !prefix.is_empty() => prefix.strip_suffix('/').unwrap_or(prefix),
_ => "",
};
let url_path = url_path.strip_prefix('/').unwrap_or(url_path);
let merged = format!("{}/{}", url_path_prefix, url_path);
let trimmed = merged.strip_suffix('/').unwrap_or(merged.as_str());
let trimmed = trimmed.strip_prefix('/').unwrap_or(trimmed);
format!("/{}", trimmed)
}
pub async fn delay_response(milliseconds: u32) {
time::sleep(Duration::from_millis(milliseconds.into())).await
}