What crosses between the runtime's Request and Response and the service's, as pure functions.
3use whiskers_service::Content;
The Content-Type a response of this kind carries, as whiskersd sends it (so every host answers
the same bytes with the same type).
The request's class for the access line: a fixed word per route, never the path as sent.
17pub fn route_class(path: &str) -> &'static str { 18 match path { 19 "/memory/sync" => "memory-sync", 20 "/household/sync" => "household-sync", 21 "/chat/sync" => "chat-sync", 22 "/check" | "/rerank" | "/embed" | "/speak" | "/speak/v2" | "/usage" | "/v1/messages" => "other-known", 23 "/journal/push" | "/journal/pull" | "/picture/missing" | "/picture/put" | "/picture/get" => "other-known", 24 p if p.starts_with("/_hub/") => "test-hub", 25 _ => "unknown", 26 } 27}
29#[cfg(test)] 30mod tests { 31 use super::*; 32 33 #[test] 34 fn each_kind_of_reply_has_the_type_the_native_server_gives_it() { 35 assert_eq!(content_type(Content::None), None); 36 assert_eq!(content_type(Content::Json), Some("application/json")); 37 assert_eq!(content_type(Content::Text), Some("text/plain; charset=UTF-8")); 38 assert_eq!(content_type(Content::Mpeg), Some("audio/mpeg")); 39 } 40 41 #[test] 42 fn a_path_is_reduced_to_a_class_and_goes_no_further() { 43 assert_eq!(route_class("/memory/sync"), "memory-sync"); 44 assert_eq!(route_class("/journal/push"), "other-known"); 45 assert_eq!(route_class("/_hub/memory/merge"), "test-hub"); 46 let c = route_class("/some/secret/path?x=1"); 47 assert_eq!(c, "unknown"); 48 } 49}