diff options
| author | 2023-03-20 22:03:02 -0400 | |
|---|---|---|
| committer | 2023-03-20 22:03:02 -0400 | |
| commit | 866dc754ae9e20cd568d03957316957c2086f342 (patch) | |
| tree | 67fc5b463557a6c2df72291240cb0cb4012919a0 | |
| parent | add callback handling (diff) | |
native: add header_callback support
| -rw-r--r-- | jurl_callbacks.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/jurl_callbacks.c b/jurl_callbacks.c index f630d89..450446c 100644 --- a/jurl_callbacks.c +++ b/jurl_callbacks.c @@ -47,6 +47,19 @@ static int progress_callback(void *clientp, return janet_truthy(res) ? CURL_PROGRESSFUNC_CONTINUE : 1; } +static size_t header_callback(char *buffer, + size_t size, + size_t nitems, + void *userdata) { + JanetFunction *fun = (JanetFunction*)userdata; + size_t realsize = size * nitems; + + Janet argv[1] = { janet_stringv((const uint8_t*)buffer, realsize), }; + janet_call(fun, 1, argv); + + return realsize; +} + static int debug_callback(CURL *handle, curl_infotype type, char *data, @@ -140,6 +153,10 @@ CURLcode jurl_setcallback(jurl_handle *jurl, CURLoption opt, JanetFunction *fun) res |= curl_easy_setopt(jurl->handle, CURLOPT_XFERINFODATA, fun); res |= curl_easy_setopt(jurl->handle, CURLOPT_XFERINFOFUNCTION, progress_callback); break; + case CURLOPT_HEADERFUNCTION: // string -> void + res |= curl_easy_setopt(jurl->handle, CURLOPT_HEADERDATA, fun); + res |= curl_easy_setopt(jurl->handle, CURLOPT_HEADERFUNCTION, header_callback); + break; case CURLOPT_DEBUGFUNCTION: // curl*, // :text | :header-in | :header-out | :data-in | :data-out | |
