From cc4203ff3ebd97bda4c5b9735f891e187665258a Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 9 Jun 2026 20:08:16 -0400 Subject: [PATCH] const def --- crates/schema/public/enums/src/common/platform_type.rs | 8 ++++++++ .../http_server/web_utils/get_request_platform_type.rs | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/schema/public/enums/src/common/platform_type.rs b/crates/schema/public/enums/src/common/platform_type.rs index b543789fb0..d1778f2c57 100644 --- a/crates/schema/public/enums/src/common/platform_type.rs +++ b/crates/schema/public/enums/src/common/platform_type.rs @@ -18,8 +18,16 @@ use utoipa::ToSchema; #[derive(Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd, Serialize, Deserialize, ToSchema)] #[serde(rename_all = "snake_case")] pub enum PlatformType { + // ========== Our clients ========== + + /// Website users Web, + + /// Desktop app users DesktopApp, + + // ========== Other clients ========== + Curl, PythonRequests, Postman, diff --git a/crates/service/web/storyteller_web/src/http_server/web_utils/get_request_platform_type.rs b/crates/service/web/storyteller_web/src/http_server/web_utils/get_request_platform_type.rs index e2ee01e16e..ee61f9b12f 100644 --- a/crates/service/web/storyteller_web/src/http_server/web_utils/get_request_platform_type.rs +++ b/crates/service/web/storyteller_web/src/http_server/web_utils/get_request_platform_type.rs @@ -21,6 +21,8 @@ const PYTHON_REQUESTS_USER_AGENT_PREFIX : &str = "python-requests"; /// (Compared case-insensitively.) const POSTMAN_USER_AGENT_PREFIX : &str = "postmanruntime"; +const USER_AGENT_HEADER_NAME : HeaderName = HeaderName::from_static("user-agent"); + /// Infer the calling platform from the request's User-Agent header. /// /// Returns `None` if the header is absent or unreadable. Otherwise, the ArtCraft @@ -28,9 +30,8 @@ const POSTMAN_USER_AGENT_PREFIX : &str = "postmanruntime"; /// CLI/API tools (curl, python-requests, Postman) are flagged as such, and /// anything else is assumed to be a browser. pub fn get_request_platform_type(http_request: &HttpRequest) -> Option { - let user_agent_header_name = HeaderName::from_static("user-agent"); let header_map : &HeaderMap = http_request.headers(); - let user_agent = header_map.get(user_agent_header_name)? + let user_agent = header_map.get(USER_AGENT_HEADER_NAME)? .to_str() .ok()?;