MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / update_cors

Function update_cors

src/ui/http_server.c:118–134  ·  view source on GitHub ↗

Foreign origins are rejected before this runs. Reflect only the exact * same-server origin; a different localhost port is a different principal. */

Source from the content-addressed store, hash-verified

116/* Foreign origins are rejected before this runs. Reflect only the exact
117 * same-server origin; a different localhost port is a different principal. */
118static void update_cors(const cbm_http_req_t *req, int port) {
119 if (req->origin[0] != '\0' && origin_is_same_server(req->origin, port)) {
120 snprintf(g_cors, sizeof(g_cors),
121 "Access-Control-Allow-Origin: %s\r\n"
122 "Access-Control-Allow-Methods: POST, GET, DELETE, OPTIONS\r\n"
123 "Access-Control-Allow-Headers: Content-Type\r\n",
124 req->origin);
125 } else {
126 /* No Access-Control-Allow-Origin → browser blocks cross-origin access */
127 snprintf(g_cors, sizeof(g_cors),
128 "Access-Control-Allow-Methods: POST, GET, DELETE, OPTIONS\r\n"
129 "Access-Control-Allow-Headers: Content-Type\r\n");
130 }
131 snprintf(g_cors_json, sizeof(g_cors_json), "%sContent-Type: application/json\r\n", g_cors);
132 snprintf(g_cors_html, sizeof(g_cors_html), "%sContent-Type: text/html; charset=utf-8\r\n",
133 g_cors);
134}
135
136static const char *detect_ui_lang(const char *accept_language) {
137 if (accept_language && (strstr(accept_language, "zh-CN") || strstr(accept_language, "zh"))) {

Callers 1

Calls 1

origin_is_same_serverFunction · 0.85

Tested by

no test coverage detected