Browse Source

More work in http signed request.

default 2 years ago
parent
commit
d2bdaf378f
3 changed files with 15 additions and 8 deletions
  1. 3 3
      http.c
  2. 11 1
      main.c
  3. 1 4
      xs_curl.h

+ 3 - 3
http.c

@@ -75,12 +75,12 @@ d_char *http_signed_request(snac *snac, char *method, char *url,
 
     /* add the new headers */
     hdrs = xs_dict_append(hdrs, "content-type", "application/activity+json");
+    hdrs = xs_dict_append(hdrs, "accept",       "application/activity+json");
     hdrs = xs_dict_append(hdrs, "date",         date);
     hdrs = xs_dict_append(hdrs, "signature",    signature);
     hdrs = xs_dict_append(hdrs, "digest",       digest);
     hdrs = xs_dict_append(hdrs, "user-agent",   "snac/2.x");
 
-//    return xs_http_request(method, url, hdrs,
-//                           body, b_size, status, payload, p_size);
-    return NULL;
+    return xs_http_request(method, url, hdrs,
+                           body, b_size, status, payload, p_size);
 }

+ 11 - 1
main.c

@@ -2,6 +2,8 @@
 /* copyright (c) 2022 grunfink - MIT license */
 
 #include "xs.h"
+#include "xs_encdec.h"
+#include "xs_json.h"
 
 #include "snac.h"
 
@@ -19,9 +21,17 @@ int main(int argc, char *argv[])
     int status;
     d_char *payload;
     int p_size;
-    http_signed_request(&snac, "GET", "https://comam.es/snac/jessie",
+    xs *response;
+
+    response = http_signed_request(&snac, "GET", "https://mastodon.social/users/VictorMoral",
         headers, NULL, 0, &status, &payload, &p_size);
 
+    {
+        xs *j1 = xs_json_dumps_pp(response, 4);
+        printf("response:\n%s\n", j1);
+        printf("payload:\n%s\n", payload);
+    }
+
     {
         xs *list = queue(&snac);
         char *p, *fn;

+ 1 - 4
xs_curl.h

@@ -138,10 +138,7 @@ d_char *xs_http_request(char *method, char *url, d_char *headers,
     /* fill the request headers */
     p = headers;
     while (xs_dict_iter(&p, &k, &v)) {
-        xs *h;
-
-        const char *args[] = { k, v, NULL };
-        h = xs_fmt("%s: %s", args);
+        xs *h = xs_fmt("%s: %s", k, v);
 
         list = curl_slist_append(list, h);
     }