diff options
author | default <nobody@localhost> | 2022-10-16 19:00:17 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2022-10-16 19:00:17 +0200 |
commit | 395f80bdc40115087e8e4eb8fdbed8520df54863 (patch) | |
tree | cb6f0132d3738456a02b5d89099dde3d7345201e | |
parent | d9a15b8af7da2bc27d4d55ee745242f5b4e39071 (diff) |
Added support for HEAD methods.
Mastodon uses them when it founds an attachment.
-rw-r--r-- | activitypub.c | 2 | ||||
-rw-r--r-- | httpd.c | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/activitypub.c b/activitypub.c index fb790d5..7ac4c5f 100644 --- a/activitypub.c +++ b/activitypub.c @@ -880,7 +880,7 @@ int activitypub_get_handler(d_char *req, char *q_path, xs *msg = NULL; if (accept == NULL) - return 400; + return 0; if (xs_str_in(accept, "application/activity+json") == -1 && xs_str_in(accept, "application/ld+json") == -1) @@ -7,6 +7,7 @@ #include "xs_json.h" #include "xs_socket.h" #include "xs_httpd.h" +#include "xs_mime.h" #include "snac.h" @@ -30,7 +31,7 @@ int server_get_handler(d_char *req, char *q_path, char *acpt = xs_dict_get(req, "accept"); if (acpt == NULL) - return 400; + return 0; /* is it the server root? */ if (*q_path == '\0') { @@ -126,7 +127,7 @@ void httpd_connection(FILE *f) if (xs_startswith(q_path, p)) q_path = xs_crop(q_path, strlen(p), 0); - if (strcmp(method, "GET") == 0) { + if (strcmp(method, "GET") == 0 || strcmp(method, "HEAD") == 0) { /* cascade through */ if (status == 0) status = server_get_handler(req, q_path, &body, &b_size, &ctype); @@ -181,6 +182,12 @@ void httpd_connection(FILE *f) if (b_size == 0 && body != NULL) b_size = strlen(body); + /* if it was a HEAD, no body will be sent */ + if (strcmp(method, "HEAD") == 0) { + free(body); + body = NULL; + } + xs_httpd_response(f, status, headers, body, b_size); fclose(f); |