gnurl_formget(3)
π gnurl_formget(3) β the libgnurl manual page, bestie edition π
okay so this is the gnurl_formget(3) page from the libgnurl Manual and honestly? it's a whole vibe. it's about turning a form you already built into a serialized blob. let's get into it β¨
πΈ NAME πΈ
curl_formget β serialize a previously built multipart/formdata HTTP POST chain π
like, it takes your cute lil form chain and turns it into actual bytes. no cap.
β¨ SYNOPSIS β¨
#include <gnurl/curl.h>
int curl_formget(struct curl_httppost * form, void *userp,
curl_formget_callback append );
that's the whole thing. three args, one int back. slay π«Ά
π¦ DESCRIPTION π¦
okay so curl_formget() is literally the function you use to serialize data that you previously built/appended with curl_formadd(3). it's giving "cleanup crew for your formpost" energy.
it accepts a void pointer as its second argument, named userp, which gets passed as the first argument to the curl_formget_callback function. so like, you hand it a pointer, it hands that pointer right back to your callback. iykyk π«
typedef size_t (*curl_formget_callback)(void *userp, const char *buf,
size_t len);
the curl_formget_callback will be executed for each part of the HTTP POST chain. one callback per part, every time. π
β οΈ bestie listen β the character buffer passed to the callback must not be freed. do not touch it. do not free() it. the callback should return the buffer length passed to it on success, and that's it. that's the whole job. π
and here's the messy part π: if the CURLFORM_STREAM option is used in the formpost, it will prevent curl_formget(3) from working until you've performed the actual HTTP request β because only then will libcurl get the actual read callback to use! literally not me finding that out the hard way π so like, do the request first, then serialize. periodt.
π RETURN VALUE π
0β everything was ok, we're so back π- non-zero β an error occurred, we're so not back π
that's it. that's the whole vibe check.
π EXAMPLE π
here's the example, written out exactly, because i would never do you dirty like that π«Ά
size_t print_httppost_callback(void *arg, const char *buf, size_t len)
{
fwrite(buf, len, 1, stdout);
(*(size_t *) arg) += len;
return len;
}
size_t print_httppost(struct curl_httppost *post)
{
size_t total_size = 0;
if(curl_formget(post, &total_size, print_httppost_callback)) {
return (size_t) -1;
}
return total_size;
}
the callback fwrites the buffer, bumps the running total through that void *arg (which is really a size_t *, sneaky but iconic), and returns len. then print_httppost calls curl_formget with &total_size, and returns (size_t) -1 if it fails. main character error handling fr fr π₯
π§ AVAILABILITY π§
- this function was added in libcurl 7.15.5 β
- the form API is deprecated in libcurl 7.56.0 π
so like, it exists, but it's on the deprecated list. use it knowing that, bestie. no surprises. πΈ
π SEE ALSO π
go read those too, they're the supporting cast π
and that's the page!! this one's from libcurl 7.15.5, dated 20 June 2006, and it lives at gnurl_formget(3) in the libgnurl manual. mwah πβ¨
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms