use const_str::concat;
use const_str::replace;
use regex_static::lazy_regex;
type Lazy<T> = regex_static::once_cell::sync::Lazy<T>;
pub type Regex = Lazy<regex::Regex>;
pub static WHITESPACE: Regex = lazy_regex!(r"\s+");
pub const PROJECT_NAME: &str = env!("CARGO_PKG_NAME");
pub const PROJECT_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const REPO_HTTP: &str = env!("CARGO_PKG_REPOSITORY");
pub const REPO_GMI: &str = replace!(REPO_HTTP, "https", "gemini");
pub static USER_AGENT: &str = const {
const REQWEST_VERSION: &str =
include_str!(core::concat!(env!("OUT_DIR"), "/reqwest_version.txt"));
#[cfg(debug_assertions)]
const DEBUG: &str = "-debug";
#[cfg(not(debug_assertions))]
const DEBUG: &str = "";
concat!(
PROJECT_NAME,
"/",
PROJECT_VERSION,
DEBUG,
" (reqwest/",
REQWEST_VERSION,
"; +",
REPO_HTTP,
")"
)
};
#[cfg(test)]
mod tests {
use super::*;
static UA_REGEX: Regex = lazy_regex!(
r"^git-gemini-forge/\d+\.\d+\.\d+(\-debug)? \(reqwest/\d+\.\d+\.\d+; \+https://[\w\./\-]+\)$"
);
#[test]
fn test_user_agent_string_is_reasonable() {
let actual = USER_AGENT;
assert!(UA_REGEX.is_match(actual), "Unexpected UA: {actual:?}");
assert!(actual.contains(REPO_HTTP));
}
}