commit 5172dc1

default  ·  2024-01-08 16:26:33 +0000 UTC
parent d053999
Webfinger queries are cached, as they should.
1 files changed,  +12, -2
+12, -2
 1@@ -46,6 +46,13 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us
 2     headers = xs_dict_append(headers, "accept",     "application/json");
 3     headers = xs_dict_append(headers, "user-agent", USER_AGENT);
 4 
 5+    xs *obj = NULL;
 6+
 7+    /* is it cached? */
 8+    if (valid_status(status = object_get(qs, &obj))) {
 9+        /* nothing more to do */
10+    }
11+    else
12     /* is it a query about one of us? */
13     if (strcmp(host, xs_dict_get(srv_config, "host")) == 0) {
14         /* route internally */
15@@ -68,9 +75,12 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us
16             http_signed_request(snac, "GET", url, headers, NULL, 0, &status, &payload, &p_size, 0);
17     }
18 
19-    if (valid_status(status)) {
20-        xs *obj = xs_json_loads(payload);
21+    if (obj == NULL && valid_status(status) && payload) {
22+        obj = xs_json_loads(payload);
23+        object_add(qs, obj);
24+    }
25 
26+    if (obj) {
27         if (user != NULL) {
28             char *subject = xs_dict_get(obj, "subject");
29