| 1939 | } |
| 1940 | |
| 1941 | static void dispatch_request(cbm_http_server_t *srv, cbm_http_conn_t *c, |
| 1942 | const cbm_http_req_t *req) { |
| 1943 | if (!request_passes_http_security(srv, c, req)) |
| 1944 | return; |
| 1945 | |
| 1946 | bool is_get = strcmp(req->method, "GET") == 0; |
| 1947 | bool is_post = strcmp(req->method, "POST") == 0; |
| 1948 | bool is_delete = strcmp(req->method, "DELETE") == 0; |
| 1949 | |
| 1950 | /* OPTIONS preflight for CORS */ |
| 1951 | if (strcmp(req->method, "OPTIONS") == 0) { |
| 1952 | cbm_http_replyf(c, 204, g_cors, "%s", ""); |
| 1953 | return; |
| 1954 | } |
| 1955 | |
| 1956 | /* Private-generation proof used only by `daemon start --open`. The |
| 1957 | * challenge is public; the HMAC key exists only in this daemon's |
| 1958 | * authenticated application and HTTP server instances. */ |
| 1959 | if (is_get && strcmp(req->path, "/__cbm/ui-readiness") == 0) { |
| 1960 | handle_ui_readiness(srv, c, req); |
| 1961 | return; |
| 1962 | } |
| 1963 | |
| 1964 | /* POST /rpc → JSON-RPC dispatch (reuses existing MCP tools) */ |
| 1965 | if (is_post && cbm_http_path_match(req->path, "/rpc")) { |
| 1966 | handle_rpc(c, req, srv->mcp); |
| 1967 | return; |
| 1968 | } |
| 1969 | |
| 1970 | /* GET /api/layout → 3D graph layout */ |
| 1971 | if (is_get && cbm_http_path_match(req->path, "/api/layout*")) { |
| 1972 | handle_layout(c, req); |
| 1973 | return; |
| 1974 | } |
| 1975 | |
| 1976 | /* GET /api/repo-info → git remote / branch for GitHub deep-links */ |
| 1977 | if (is_get && cbm_http_path_match(req->path, "/api/repo-info*")) { |
| 1978 | handle_repo_info(c, req); |
| 1979 | return; |
| 1980 | } |
| 1981 | |
| 1982 | /* POST /api/index → start background indexing */ |
| 1983 | if (is_post && cbm_http_path_match(req->path, "/api/index")) { |
| 1984 | handle_index_start(srv, c, req); |
| 1985 | return; |
| 1986 | } |
| 1987 | |
| 1988 | /* GET /api/index-status → check indexing progress */ |
| 1989 | if (is_get && cbm_http_path_match(req->path, "/api/index-status")) { |
| 1990 | handle_index_status(srv, c); |
| 1991 | return; |
| 1992 | } |
| 1993 | |
| 1994 | /* GET /api/ui-config → language and local UI preferences */ |
| 1995 | if (is_get && cbm_http_path_match(req->path, "/api/ui-config")) { |
| 1996 | handle_ui_config(c, req); |
| 1997 | return; |
| 1998 | } |
no test coverage detected