fix: add missing runtime functions (native_str_to_int, http_post_json_with_headers) #15
@@ -292,6 +292,10 @@ el_val_t str_to_int(el_val_t sv) {
|
||||
return (el_val_t)atoll(s);
|
||||
}
|
||||
|
||||
/* native_str_to_int — El compiler-generated alias for str_to_int.
|
||||
* Converts a string el_val_t to its integer representation. */
|
||||
el_val_t native_str_to_int(el_val_t sv) { return str_to_int(sv); }
|
||||
|
||||
el_val_t str_slice(el_val_t sv, el_val_t start, el_val_t end) {
|
||||
const char* s = EL_CSTR(sv);
|
||||
if (!s) return el_wrap_str(el_strdup(""));
|
||||
@@ -907,6 +911,33 @@ el_val_t http_post_with_headers(el_val_t url, el_val_t body, el_val_t headers_ma
|
||||
return r;
|
||||
}
|
||||
|
||||
/* http_post_json_with_headers — POST with Content-Type: application/json plus
|
||||
* any additional headers supplied as an El map. Combines http_post_json and
|
||||
* http_post_with_headers: the Content-Type header is always prepended so
|
||||
* callers do not have to include it in their map. */
|
||||
el_val_t http_post_json_with_headers(el_val_t url, el_val_t headers_map, el_val_t json_body) {
|
||||
struct curl_slist* h = NULL;
|
||||
h = curl_slist_append(h, "Content-Type: application/json");
|
||||
/* Append caller-supplied headers from the map */
|
||||
ElMap* m = as_map(headers_map);
|
||||
if (m) {
|
||||
for (int64_t i = 0; i < m->count; i++) {
|
||||
const char* k = EL_CSTR(m->keys[i]);
|
||||
const char* v = EL_CSTR(m->values[i]);
|
||||
if (!k || !v) continue;
|
||||
size_t n = strlen(k) + strlen(v) + 4;
|
||||
char* line = malloc(n);
|
||||
if (!line) continue;
|
||||
snprintf(line, n, "%s: %s", k, v);
|
||||
h = curl_slist_append(h, line);
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
el_val_t r = http_do("POST", EL_CSTR(url), EL_CSTR(json_body), h);
|
||||
curl_slist_free_all(h);
|
||||
return r;
|
||||
}
|
||||
|
||||
el_val_t http_post_form_auth(el_val_t url, el_val_t form_body, el_val_t auth_header) {
|
||||
struct curl_slist* h = NULL;
|
||||
h = curl_slist_append(h, "Content-Type: application/x-www-form-urlencoded");
|
||||
@@ -11195,6 +11226,7 @@ el_val_t http_post(el_val_t url, el_val_t body) { (void)url; (void)body
|
||||
el_val_t http_post_json(el_val_t url, el_val_t body) { (void)url; (void)body; return _no_curl_err(); }
|
||||
el_val_t http_get_with_headers(el_val_t url, el_val_t h) { (void)url; (void)h; return _no_curl_err(); }
|
||||
el_val_t http_post_with_headers(el_val_t url, el_val_t b, el_val_t h) { (void)url; (void)b; (void)h; return _no_curl_err(); }
|
||||
el_val_t http_post_json_with_headers(el_val_t url, el_val_t h, el_val_t b) { (void)url; (void)h; (void)b; return _no_curl_err(); }
|
||||
el_val_t http_post_form_auth(el_val_t url, el_val_t b, el_val_t a) { (void)url; (void)b; (void)a; return _no_curl_err(); }
|
||||
el_val_t http_delete(el_val_t url) { (void)url; return _no_curl_err(); }
|
||||
el_val_t http_patch(el_val_t url, el_val_t body) { (void)url; (void)body; return _no_curl_err(); }
|
||||
|
||||
@@ -95,6 +95,7 @@ el_val_t str_len(el_val_t s);
|
||||
el_val_t str_concat(el_val_t a, el_val_t b);
|
||||
el_val_t int_to_str(el_val_t n);
|
||||
el_val_t str_to_int(el_val_t s);
|
||||
el_val_t native_str_to_int(el_val_t s);
|
||||
el_val_t str_slice(el_val_t s, el_val_t start, el_val_t end);
|
||||
el_val_t str_contains(el_val_t s, el_val_t sub);
|
||||
el_val_t str_replace(el_val_t s, el_val_t from, el_val_t to);
|
||||
@@ -149,6 +150,7 @@ el_val_t http_post(el_val_t url, el_val_t body);
|
||||
el_val_t http_post_json(el_val_t url, el_val_t json_body);
|
||||
el_val_t http_get_with_headers(el_val_t url, el_val_t headers_map);
|
||||
el_val_t http_post_with_headers(el_val_t url, el_val_t body, el_val_t headers_map);
|
||||
el_val_t http_post_json_with_headers(el_val_t url, el_val_t headers_map, el_val_t json_body);
|
||||
el_val_t http_post_form_auth(el_val_t url, el_val_t form_body, el_val_t auth_header);
|
||||
el_val_t http_delete(el_val_t url);
|
||||
void http_serve(el_val_t port, el_val_t handler);
|
||||
|
||||
Reference in New Issue
Block a user