commit 7e27ccf
default
·
2023-02-14 07:15:38 +0000 UTC
parent 296625c
Try to show a piece of the error after connecting.
2 files changed,
+27,
-3
M
httpd.c
+26,
-2
1@@ -1180,7 +1180,22 @@ void process_queue_item(xs_dict *q_item)
2 /* deliver */
3 status = send_to_inbox_raw(keyid, seckey, inbox, msg, &payload, &p_size, retries == 0 ? 3 : 8);
4
5- srv_log(xs_fmt("output message: sent to inbox %s %d", inbox, status));
6+ if (payload && !valid_status(status)) {
7+ /* in case of error, print a part of the payload,
8+ as it may be informative */
9+ if (p_size > 24) {
10+ /* trim the message */
11+ payload[24] = '\0';
12+ payload = xs_str_cat(payload, "...");
13+ }
14+
15+ payload = xs_str_wrap_i(" (", payload, ")");
16+ }
17+
18+ if (payload == NULL)
19+ payload = xs_str_new(NULL);
20+
21+ srv_log(xs_fmt("output message: sent to inbox %s %d%s", inbox, status, payload));
22
23 if (!valid_status(status)) {
24 retries++;
25@@ -1377,8 +1392,11 @@ int activitypub_post_handler(d_char *req, char *q_path,
26 snac snac;
27 char *v;
28
29- if (i_ctype == NULL)
30+ if (i_ctype == NULL) {
31+ *body = xs_str_new("no content-type");
32+ *ctype = "text/plain";
33 return 400;
34+ }
35
36 if (xs_str_in(i_ctype, "application/activity+json") == -1 &&
37 xs_str_in(i_ctype, "application/ld+json") == -1)
38@@ -1389,6 +1407,9 @@ int activitypub_post_handler(d_char *req, char *q_path,
39
40 if (msg == NULL) {
41 srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path));
42+
43+ *body = xs_str_new("JSON error");
44+ *ctype = "text/plain";
45 status = 400;
46 }
47
48@@ -1417,6 +1438,9 @@ int activitypub_post_handler(d_char *req, char *q_path,
49
50 if (strcmp(s2, v) != 0) {
51 srv_log(xs_fmt("digest check FAILED"));
52+
53+ *body = xs_str_new("bad digest");
54+ *ctype = "text/plain";
55 status = 400;
56 }
57 }
M
httpd.c
+1,
-1
1@@ -198,7 +198,7 @@ void httpd_connection(FILE *f)
2 if (status == 404)
3 body = xs_str_new("<h1>404 Not Found</h1>");
4
5- if (status == 400)
6+ if (status == 400 && body != NULL)
7 body = xs_str_new("<h1>400 Bad Request</h1>");
8
9 if (status == 303)