Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion kinode/src/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type WsPathBindings = Arc<RwLock<Router<BoundWsPath>>>;

struct BoundPath {
pub app: ProcessId,
pub path: String,
pub secure_subdomain: Option<String>,
pub authenticated: bool,
pub local_only: bool,
Expand Down Expand Up @@ -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<BoundPath> = 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
Expand Down Expand Up @@ -584,6 +587,11 @@ async fn http_handler(
}
} else {
// otherwise, make a message to the correct app
let url_params: HashMap<String, String> = route
.params()
.into_iter()
.map(|(key, value)| (key.to_string(), value.to_string()))
.collect();
(
KernelMessage {
id,
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/http/server_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ pub struct IncomingHttpRequest {
pub source_socket_addr: Option<String>, // 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<String, String>,
pub url_params: HashMap<String, String>, // comes from route-recognizer
pub query_params: HashMap<String, String>,
// BODY is stored in the lazy_load_blob, as bytes
}
Expand Down