summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2022-10-16 19:00:17 +0200
committerGravatar default2022-10-16 19:00:17 +0200
commit395f80bdc40115087e8e4eb8fdbed8520df54863 (patch)
treecb6f0132d3738456a02b5d89099dde3d7345201e
parentAttachments are now starting to get real. (diff)
downloadsnac2-395f80bdc40115087e8e4eb8fdbed8520df54863.tar.gz
snac2-395f80bdc40115087e8e4eb8fdbed8520df54863.tar.xz
snac2-395f80bdc40115087e8e4eb8fdbed8520df54863.zip
Added support for HEAD methods.
Mastodon uses them when it founds an attachment.
-rw-r--r--activitypub.c2
-rw-r--r--httpd.c11
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,
880 xs *msg = NULL; 880 xs *msg = NULL;
881 881
882 if (accept == NULL) 882 if (accept == NULL)
883 return 400; 883 return 0;
884 884
885 if (xs_str_in(accept, "application/activity+json") == -1 && 885 if (xs_str_in(accept, "application/activity+json") == -1 &&
886 xs_str_in(accept, "application/ld+json") == -1) 886 xs_str_in(accept, "application/ld+json") == -1)
diff --git a/httpd.c b/httpd.c
index d30d05b..4233057 100644
--- a/httpd.c
+++ b/httpd.c
@@ -7,6 +7,7 @@
7#include "xs_json.h" 7#include "xs_json.h"
8#include "xs_socket.h" 8#include "xs_socket.h"
9#include "xs_httpd.h" 9#include "xs_httpd.h"
10#include "xs_mime.h"
10 11
11#include "snac.h" 12#include "snac.h"
12 13
@@ -30,7 +31,7 @@ int server_get_handler(d_char *req, char *q_path,
30 char *acpt = xs_dict_get(req, "accept"); 31 char *acpt = xs_dict_get(req, "accept");
31 32
32 if (acpt == NULL) 33 if (acpt == NULL)
33 return 400; 34 return 0;
34 35
35 /* is it the server root? */ 36 /* is it the server root? */
36 if (*q_path == '\0') { 37 if (*q_path == '\0') {
@@ -126,7 +127,7 @@ void httpd_connection(FILE *f)
126 if (xs_startswith(q_path, p)) 127 if (xs_startswith(q_path, p))
127 q_path = xs_crop(q_path, strlen(p), 0); 128 q_path = xs_crop(q_path, strlen(p), 0);
128 129
129 if (strcmp(method, "GET") == 0) { 130 if (strcmp(method, "GET") == 0 || strcmp(method, "HEAD") == 0) {
130 /* cascade through */ 131 /* cascade through */
131 if (status == 0) 132 if (status == 0)
132 status = server_get_handler(req, q_path, &body, &b_size, &ctype); 133 status = server_get_handler(req, q_path, &body, &b_size, &ctype);
@@ -181,6 +182,12 @@ void httpd_connection(FILE *f)
181 if (b_size == 0 && body != NULL) 182 if (b_size == 0 && body != NULL)
182 b_size = strlen(body); 183 b_size = strlen(body);
183 184
185 /* if it was a HEAD, no body will be sent */
186 if (strcmp(method, "HEAD") == 0) {
187 free(body);
188 body = NULL;
189 }
190
184 xs_httpd_response(f, status, headers, body, b_size); 191 xs_httpd_response(f, status, headers, body, b_size);
185 192
186 fclose(f); 193 fclose(f);