diff --git a/Cargo.lock b/Cargo.lock index 6e11ebd2..db9baeda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2578,6 +2578,7 @@ dependencies = [ "open", "public-ip", "rand 0.8.5", + "regex", "reqwest", "ring 0.16.20", "rmp-serde", diff --git a/kinode/src/http/server.rs b/kinode/src/http/server.rs index 0453af36..51213efb 100644 --- a/kinode/src/http/server.rs +++ b/kinode/src/http/server.rs @@ -41,6 +41,7 @@ type WsPathBindings = Arc>>; struct BoundPath { pub app: ProcessId, + pub path: String, pub secure_subdomain: Option, pub authenticated: bool, pub local_only: bool, @@ -185,17 +186,19 @@ pub async fn http_server( let jwt_secret_bytes = Arc::new(jwt_secret_bytes); let http_response_senders: HttpResponseSenders = Arc::new(DashMap::new()); let ws_senders: WebSocketSenders = Arc::new(DashMap::new()); + let path = format!("/rpc:distro:sys/message"); // add RPC path let mut bindings_map: Router = Router::new(); let rpc_bound_path = BoundPath { app: ProcessId::new(Some("rpc"), "distro", "sys"), + path: path.clone(), secure_subdomain: None, // TODO maybe RPC should have subdomain? authenticated: false, local_only: true, static_content: None, }; - bindings_map.add("/rpc:distro:sys/message", rpc_bound_path); + bindings_map.add(&path, rpc_bound_path); let path_bindings: PathBindings = Arc::new(RwLock::new(bindings_map)); // ws path bindings @@ -584,6 +587,11 @@ async fn http_handler( } } else { // otherwise, make a message to the correct app + let url_params: HashMap = route + .params() + .into_iter() + .map(|(key, value)| (key.to_string(), value.to_string())) + .collect(); ( KernelMessage { id, @@ -607,7 +615,9 @@ async fn http_handler( host.unwrap_or(Authority::from_static("localhost")), original_path ), + bound_path: bound_path.path.clone(), headers: serialized_headers, + url_params, query_params, })) .unwrap(), @@ -1138,6 +1148,7 @@ async fn handle_app_message( &normalize_path(&path), BoundPath { app: km.source.process.clone(), + path: path.clone(), secure_subdomain: None, authenticated, local_only, @@ -1160,6 +1171,7 @@ async fn handle_app_message( &normalize_path(&path), BoundPath { app: km.source.process.clone(), + path: path.clone(), secure_subdomain: None, authenticated, local_only, @@ -1183,6 +1195,7 @@ async fn handle_app_message( &normalize_path(&path), BoundPath { app: km.source.process.clone(), + path: path.clone(), secure_subdomain: Some(subdomain), authenticated: true, local_only: false, @@ -1205,6 +1218,7 @@ async fn handle_app_message( &normalize_path(&path), BoundPath { app: km.source.process.clone(), + path: path.clone(), secure_subdomain: Some(subdomain), authenticated: true, local_only: false, diff --git a/lib/src/http/server_types.rs b/lib/src/http/server_types.rs index ed0a90f5..363b00e4 100644 --- a/lib/src/http/server_types.rs +++ b/lib/src/http/server_types.rs @@ -32,7 +32,9 @@ pub struct IncomingHttpRequest { pub source_socket_addr: Option, // will parse to SocketAddr pub method: String, // will parse to http::Method pub url: String, // will parse to url::Url + pub bound_path: String, // the path that was originally bound pub headers: HashMap, + pub url_params: HashMap, // comes from route-recognizer pub query_params: HashMap, // BODY is stored in the lazy_load_blob, as bytes }