Enforce DELETE request

This commit is contained in:
robert committed 2026-11-10 13:52:12 +02:00
1 parent 706f4787e2
commit b4ca50b3c6
3 files changed
+25 -6

No files matched your search

+5 -1
View File
@@ -1969,7 +1969,11 @@ void mg_dash_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
mg_serve_fs(c, hm, u, false);
} else if (mg_match(hm->uri, mg_str("/api/del/*/*/*"), parts) ||
mg_match(hm->uri, mg_str("/api/del/*/*"), parts)) {
mg_dash_handle_del(c, dash, u, parts);
if (mg_strcmp(hm->method, mg_str("DELETE")) == 0) {
mg_dash_handle_del(c, dash, u, parts);
} else {
mg_http_reply(c, 405, "Allow: DELETE\r\n", "Method Not Allowed\n");
}
} else if (mg_match(hm->uri, mg_str("/api/add/*"), parts)) {
mg_dash_handle_add(c, dash, u, parts, hm->body);
} else if (mg_match(hm->uri, mg_str("/api/get/*/*"), parts) &&
+5 -1
View File
@@ -609,7 +609,11 @@ void mg_dash_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
mg_serve_fs(c, hm, u, false);
} else if (mg_match(hm->uri, mg_str("/api/del/*/*/*"), parts) ||
mg_match(hm->uri, mg_str("/api/del/*/*"), parts)) {
mg_dash_handle_del(c, dash, u, parts);
if (mg_strcmp(hm->method, mg_str("DELETE")) == 0) {
mg_dash_handle_del(c, dash, u, parts);
} else {
mg_http_reply(c, 405, "Allow: DELETE\r\n", "Method Not Allowed\n");
}
} else if (mg_match(hm->uri, mg_str("/api/add/*"), parts)) {
mg_dash_handle_add(c, dash, u, parts, hm->body);
} else if (mg_match(hm->uri, mg_str("/api/get/*/*"), parts) &&
+15 -4
View File
@@ -5246,26 +5246,37 @@ static void test_dash(void) {
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 200);
ASSERT(cmpbody(buf, arr0_2_expected) == 0);
// Array deletion: single element
s_arr_index = 7;
ASSERT(fetch(&mgr, buf, url,
"GET /api/del/arr/3 HTTP/1.0\n"
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 405);
ASSERT(strstr(buf, "Allow: DELETE\r\n") != NULL);
ASSERT(s_arr_index == 7);
ASSERT(fetch(&mgr, buf, url,
"GET /api/del/arr/1/3 HTTP/1.0\n"
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 405);
ASSERT(s_arr_index == 7);
// Array deletion: single element
ASSERT(fetch(&mgr, buf, url,
"DELETE /api/del/arr/3 HTTP/1.0\n"
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 200);
ASSERT(cmpbody(buf, "1\n") == 0);
// Array deletion: range
ASSERT(fetch(&mgr, buf, url,
"GET /api/del/arr/1/3 HTTP/1.0\n"
"DELETE /api/del/arr/1/3 HTTP/1.0\n"
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 200);
ASSERT(cmpbody(buf, "3\n") == 0);
// Array deletion: out-of-range returns 403
ASSERT(fetch(&mgr, buf, url,
"GET /api/del/arr/100 HTTP/1.0\n"
"DELETE /api/del/arr/100 HTTP/1.0\n"
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 403);
// Non-array set returns 404
ASSERT(fetch(&mgr, buf, url,
"GET /api/del/set1/0 HTTP/1.0\n"
"DELETE /api/del/set1/0 HTTP/1.0\n"
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 404);
// Test that array change notification uses "arr/INDEX" key format