summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-02-14 08:15:38 +0100
committerdefault <nobody@localhost>2023-02-14 08:15:43 +0100
commit7e27ccfde8ec9d7d9edb9febdd54796ff3eae97c (patch)
treeba88d90c46e7ade02952dccd2d8d1a6e4a79079c
parent296625c3a48412689c3fd0a8ee1cfd612e95d1a0 (diff)
Try to show a piece of the error after connecting.
-rw-r--r--activitypub.c28
-rw-r--r--httpd.c2
2 files changed, 27 insertions, 3 deletions
diff --git a/activitypub.c b/activitypub.c
index f6660db..75b84ec 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -1180,7 +1180,22 @@ void process_queue_item(xs_dict *q_item)
/* deliver */
status = send_to_inbox_raw(keyid, seckey, inbox, msg, &payload, &p_size, retries == 0 ? 3 : 8);
- srv_log(xs_fmt("output message: sent to inbox %s %d", inbox, status));
+ if (payload && !valid_status(status)) {
+ /* in case of error, print a part of the payload,
+ as it may be informative */
+ if (p_size > 24) {
+ /* trim the message */
+ payload[24] = '\0';
+ payload = xs_str_cat(payload, "...");
+ }
+
+ payload = xs_str_wrap_i(" (", payload, ")");
+ }
+
+ if (payload == NULL)
+ payload = xs_str_new(NULL);
+
+ srv_log(xs_fmt("output message: sent to inbox %s %d%s", inbox, status, payload));
if (!valid_status(status)) {
retries++;
@@ -1377,8 +1392,11 @@ int activitypub_post_handler(d_char *req, char *q_path,
snac snac;
char *v;
- if (i_ctype == NULL)
+ if (i_ctype == NULL) {
+ *body = xs_str_new("no content-type");
+ *ctype = "text/plain";
return 400;
+ }
if (xs_str_in(i_ctype, "application/activity+json") == -1 &&
xs_str_in(i_ctype, "application/ld+json") == -1)
@@ -1389,6 +1407,9 @@ int activitypub_post_handler(d_char *req, char *q_path,
if (msg == NULL) {
srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path));
+
+ *body = xs_str_new("JSON error");
+ *ctype = "text/plain";
status = 400;
}
@@ -1417,6 +1438,9 @@ int activitypub_post_handler(d_char *req, char *q_path,
if (strcmp(s2, v) != 0) {
srv_log(xs_fmt("digest check FAILED"));
+
+ *body = xs_str_new("bad digest");
+ *ctype = "text/plain";
status = 400;
}
}
diff --git a/httpd.c b/httpd.c
index b952edc..8c5e092 100644
--- a/httpd.c
+++ b/httpd.c
@@ -198,7 +198,7 @@ void httpd_connection(FILE *f)
if (status == 404)
body = xs_str_new("<h1>404 Not Found</h1>");
- if (status == 400)
+ if (status == 400 && body != NULL)
body = xs_str_new("<h1>400 Bad Request</h1>");
if (status == 303)