diff options
author | grunfink <grunfink@noreply.codeberg.org> | 2024-05-30 08:44:54 +0000 |
---|---|---|
committer | grunfink <grunfink@noreply.codeberg.org> | 2024-05-30 08:44:54 +0000 |
commit | d56d4beb90f613b82ebf705a3e81a667b9601860 (patch) | |
tree | 5998501d0ea9a09f26db65e2d29fcb0927b5eee0 /httpd.c | |
parent | 5bc2017ba065337dd15aa280ca0a43855b7b507b (diff) | |
parent | af8f1ef273e457318cb48f198e73c59e57373723 (diff) |
Merge pull request 'Mastodon PATCH API for user profile updates' (#169) from louis77/snac2:master into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/169
Diffstat (limited to 'httpd.c')
-rw-r--r-- | httpd.c | 38 |
1 files changed, 24 insertions, 14 deletions
@@ -217,17 +217,17 @@ int server_get_handler(xs_dict *req, const char *q_path, *body = greeting_html(); if (*body) - status = 200; + status = HTTP_STATUS_OK; } else if (strcmp(q_path, "/susie.png") == 0 || strcmp(q_path, "/favicon.ico") == 0 ) { - status = 200; + status = HTTP_STATUS_OK; *body = xs_base64_dec(default_avatar_base64(), b_size); *ctype = "image/png"; } else if (strcmp(q_path, "/.well-known/nodeinfo") == 0) { - status = 200; + status = HTTP_STATUS_OK; *ctype = "application/json; charset=utf-8"; *body = xs_fmt("{\"links\":[" "{\"rel\":\"http:/" "/nodeinfo.diaspora.software/ns/schema/2.0\"," @@ -236,7 +236,7 @@ int server_get_handler(xs_dict *req, const char *q_path, } else if (strcmp(q_path, "/.well-known/host-meta") == 0) { - status = 200; + status = HTTP_STATUS_OK; *ctype = "application/xrd+xml"; *body = xs_fmt("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<XRD>" @@ -245,13 +245,13 @@ int server_get_handler(xs_dict *req, const char *q_path, } else if (strcmp(q_path, "/nodeinfo_2_0") == 0) { - status = 200; + status = HTTP_STATUS_OK; *ctype = "application/json; charset=utf-8"; *body = nodeinfo_2_0(); } else if (strcmp(q_path, "/robots.txt") == 0) { - status = 200; + status = HTTP_STATUS_OK; *ctype = "text/plain"; *body = xs_str_new("User-agent: *\n" "Disallow: /\n"); @@ -362,8 +362,18 @@ void httpd_connection(FILE *f) } else + if (strcmp(method, "PATCH") == 0) { + +#ifndef NO_MASTODON_API + if (status == 0) + status = mastoapi_patch_handler(req, q_path, + payload, p_size, &body, &b_size, &ctype); +#endif + + } + else if (strcmp(method, "OPTIONS") == 0) { - status = 200; + status = HTTP_STATUS_OK; } else if (strcmp(method, "DELETE") == 0) { @@ -378,22 +388,22 @@ void httpd_connection(FILE *f) if (status == 0) { srv_archive_error("unattended_method", "unattended method", req, payload); srv_debug(1, xs_fmt("httpd_connection unattended %s %s", method, q_path)); - status = 404; + status = HTTP_STATUS_NOT_FOUND; } - if (status == 403) + if (status == HTTP_STATUS_FORBIDDEN) body = xs_str_new("<h1>403 Forbidden</h1>"); - if (status == 404) + if (status == HTTP_STATUS_NOT_FOUND) body = xs_str_new("<h1>404 Not Found</h1>"); - if (status == 400 && body != NULL) + if (status == HTTP_STATUS_BAD_REQUEST && body != NULL) body = xs_str_new("<h1>400 Bad Request</h1>"); - if (status == 303) + if (status == HTTP_STATUS_SEE_OTHER) headers = xs_dict_append(headers, "location", body); - if (status == 401) { + if (status == HTTP_STATUS_UNAUTHORIZED) { xs *www_auth = xs_fmt("Basic realm=\"@%s@%s snac login\"", body, xs_dict_get(srv_config, "host")); @@ -432,7 +442,7 @@ void httpd_connection(FILE *f) if (p_state->use_fcgi) xs_fcgi_response(f, status, headers, body, b_size, fcgi_id); else - xs_httpd_response(f, status, headers, body, b_size); + xs_httpd_response(f, status, http_status_text(status), headers, body, b_size); fclose(f); |