commit c3fb6ba
James Seward
·
2024-01-11 13:38:08 +0000 UTC
parent ca27d02
Support DELETE for Mastodon subscriptions While testing Mona, I noticed that after deleting my account entry for my snac server, Mona would repeatedly try to delete the subscription it thought it had created, resulting in many unhandled DELETE calls. This accepts the call and returns 200 for it, which makes Mona happy.
3 files changed,
+26,
-0
M
httpd.c
+8,
-0
1@@ -344,6 +344,14 @@ void httpd_connection(FILE *f)
2 if (strcmp(method, "OPTIONS") == 0) {
3 status = 200;
4 }
5+ else
6+ if (strcmp(method, "DELETE") == 0) {
7+#ifndef NO_MASTODON_API
8+ if (status == 0)
9+ status = mastoapi_delete_handler(req, q_path,
10+ &body, &b_size, &ctype);
11+#endif
12+ }
13
14 /* unattended? it's an error */
15 if (status == 0) {
+16,
-0
1@@ -2484,6 +2484,22 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
2 }
3
4
5+int mastoapi_delete_handler(const xs_dict *req, const char *q_path,
6+ char **body, int *b_size, char **ctype) {
7+
8+ if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/"))
9+ return 0;
10+
11+ srv_debug(1, xs_fmt("mastoapi_delete_handler %s", q_path));
12+ xs *cmd = xs_replace_n(q_path, "/api", "", 1);
13+ if (xs_startswith(cmd, "/v1/push/subscription") || xs_startswith(cmd, "/v2/push/subscription")) { /** **/
14+ // pretend we deleted it, since it doesn't exist anyway
15+ return 200;
16+ }
17+ return 0;
18+}
19+
20+
21 int mastoapi_put_handler(const xs_dict *req, const char *q_path,
22 const char *payload, int p_size,
23 char **body, int *b_size, char **ctype)
M
snac.h
+2,
-0
1@@ -312,6 +312,8 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
2 char **body, int *b_size, char **ctype);
3 int mastoapi_get_handler(const xs_dict *req, const char *q_path,
4 char **body, int *b_size, char **ctype);
5+int mastoapi_delete_handler(const xs_dict *req, const char *q_path,
6+ char **body, int *b_size, char **ctype);
7 int mastoapi_post_handler(const xs_dict *req, const char *q_path,
8 const char *payload, int p_size,
9 char **body, int *b_size, char **ctype);