mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-25 20:28:27 +00:00
3 files changed
+25
-6
No files matched your search
+5
-1
@@ -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);
|
mg_serve_fs(c, hm, u, false);
|
||||||
} else if (mg_match(hm->uri, mg_str("/api/del/*/*/*"), parts) ||
|
} else if (mg_match(hm->uri, mg_str("/api/del/*/*/*"), parts) ||
|
||||||
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)) {
|
} else if (mg_match(hm->uri, mg_str("/api/add/*"), parts)) {
|
||||||
mg_dash_handle_add(c, dash, u, parts, hm->body);
|
mg_dash_handle_add(c, dash, u, parts, hm->body);
|
||||||
} else if (mg_match(hm->uri, mg_str("/api/get/*/*"), parts) &&
|
} else if (mg_match(hm->uri, mg_str("/api/get/*/*"), parts) &&
|
||||||
|
|||||||
+5
-1
@@ -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);
|
mg_serve_fs(c, hm, u, false);
|
||||||
} else if (mg_match(hm->uri, mg_str("/api/del/*/*/*"), parts) ||
|
} else if (mg_match(hm->uri, mg_str("/api/del/*/*/*"), parts) ||
|
||||||
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)) {
|
} else if (mg_match(hm->uri, mg_str("/api/add/*"), parts)) {
|
||||||
mg_dash_handle_add(c, dash, u, parts, hm->body);
|
mg_dash_handle_add(c, dash, u, parts, hm->body);
|
||||||
} else if (mg_match(hm->uri, mg_str("/api/get/*/*"), parts) &&
|
} else if (mg_match(hm->uri, mg_str("/api/get/*/*"), parts) &&
|
||||||
|
|||||||
+15
-4
@@ -5246,26 +5246,37 @@ static void test_dash(void) {
|
|||||||
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 200);
|
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 200);
|
||||||
ASSERT(cmpbody(buf, arr0_2_expected) == 0);
|
ASSERT(cmpbody(buf, arr0_2_expected) == 0);
|
||||||
|
|
||||||
// Array deletion: single element
|
s_arr_index = 7;
|
||||||
ASSERT(fetch(&mgr, buf, url,
|
ASSERT(fetch(&mgr, buf, url,
|
||||||
"GET /api/del/arr/3 HTTP/1.0\n"
|
"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);
|
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 200);
|
||||||
ASSERT(cmpbody(buf, "1\n") == 0);
|
ASSERT(cmpbody(buf, "1\n") == 0);
|
||||||
|
|
||||||
// Array deletion: range
|
// Array deletion: range
|
||||||
ASSERT(fetch(&mgr, buf, url,
|
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);
|
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 200);
|
||||||
ASSERT(cmpbody(buf, "3\n") == 0);
|
ASSERT(cmpbody(buf, "3\n") == 0);
|
||||||
|
|
||||||
// Array deletion: out-of-range returns 403
|
// Array deletion: out-of-range returns 403
|
||||||
ASSERT(fetch(&mgr, buf, url,
|
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);
|
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 403);
|
||||||
|
|
||||||
// Non-array set returns 404
|
// Non-array set returns 404
|
||||||
ASSERT(fetch(&mgr, buf, url,
|
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);
|
"Authorization: Basic YWRtaW46YWRtaW4=\n\n") == 404);
|
||||||
|
|
||||||
// Test that array change notification uses "arr/INDEX" key format
|
// Test that array change notification uses "arr/INDEX" key format
|
||||||
|
|||||||
Reference in new issue
Block a user