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.
This commit is contained in:
James Seward 2024-01-11 13:38:08 +00:00
parent ca27d0248a
commit c3fb6bab77
3 changed files with 26 additions and 0 deletions

View File

@ -344,6 +344,14 @@ void httpd_connection(FILE *f)
if (strcmp(method, "OPTIONS") == 0) { if (strcmp(method, "OPTIONS") == 0) {
status = 200; status = 200;
} }
else
if (strcmp(method, "DELETE") == 0) {
#ifndef NO_MASTODON_API
if (status == 0)
status = mastoapi_delete_handler(req, q_path,
&body, &b_size, &ctype);
#endif
}
/* unattended? it's an error */ /* unattended? it's an error */
if (status == 0) { if (status == 0) {

View File

@ -2484,6 +2484,22 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
} }
int mastoapi_delete_handler(const xs_dict *req, const char *q_path,
char **body, int *b_size, char **ctype) {
if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/"))
return 0;
srv_debug(1, xs_fmt("mastoapi_delete_handler %s", q_path));
xs *cmd = xs_replace_n(q_path, "/api", "", 1);
if (xs_startswith(cmd, "/v1/push/subscription") || xs_startswith(cmd, "/v2/push/subscription")) { /** **/
// pretend we deleted it, since it doesn't exist anyway
return 200;
}
return 0;
}
int mastoapi_put_handler(const xs_dict *req, const char *q_path, int mastoapi_put_handler(const xs_dict *req, const char *q_path,
const char *payload, int p_size, const char *payload, int p_size,
char **body, int *b_size, char **ctype) char **body, int *b_size, char **ctype)

2
snac.h
View File

@ -312,6 +312,8 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
char **body, int *b_size, char **ctype); char **body, int *b_size, char **ctype);
int mastoapi_get_handler(const xs_dict *req, const char *q_path, int mastoapi_get_handler(const xs_dict *req, const char *q_path,
char **body, int *b_size, char **ctype); char **body, int *b_size, char **ctype);
int mastoapi_delete_handler(const xs_dict *req, const char *q_path,
char **body, int *b_size, char **ctype);
int mastoapi_post_handler(const xs_dict *req, const char *q_path, int mastoapi_post_handler(const xs_dict *req, const char *q_path,
const char *payload, int p_size, const char *payload, int p_size,
char **body, int *b_size, char **ctype); char **body, int *b_size, char **ctype);