commit 997b17d
default
·
2023-04-23 13:37:09 +0000 UTC
parent 177bf03
Moved JSON output validation to httpd.c.
2 files changed,
+10,
-8
M
httpd.c
M
httpd.c
+10,
-0
1@@ -266,6 +266,16 @@ void httpd_connection(FILE *f)
2
3 srv_archive("RECV", NULL, req, payload, p_size, status, headers, body, b_size);
4
5+ /* JSON validation check */
6+ if (strcmp(ctype, "application/json") == 0) {
7+ xs *j = xs_json_loads(body);
8+
9+ if (j == NULL) {
10+ srv_log(xs_fmt("bad JSON"));
11+ srv_archive_error("bad_json", "bad JSON", req, body);
12+ }
13+ }
14+
15 xs_free(body);
16 }
17
+0,
-8
1@@ -900,14 +900,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 *ctype = "application/json";
3 status = 200;
4
5- {
6- xs *j = xs_json_loads(*body);
7- if (j == NULL) {
8- srv_log(xs_fmt("mastoapi timeline: bad JSON"));
9- srv_archive_error("mastoapi_timeline", "bad JSON", req, *body);
10- }
11- }
12-
13 srv_debug(2, xs_fmt("mastoapi timeline: returned %d entries", xs_list_len(out)));
14 }
15 else {