CURLOPT_PREREQDATA(3)
π CURLOPT_PREREQDATA(3) π
okay so real talk, bestie β welcome to the CURLOPT_PREREQDATA page from the Library Functions Manual. Yes, that's the whole title, yes I'm folding it in right here at the top so we can get to the good stuff. Let's go β¨
π NAME π
CURLOPT_PREREQDATA β the lil' pointer you get to pass to the pre-request callback π«Ά
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PREREQDATA, void *pointer);
β¨ DESCRIPTION β¨
So here's the vibe: you hand libcurl a pointer, and libcurl is like "cool, not mine, not touching it π
" β it literally leaves it alone, untouched. Then it passes that exact same pointer as the first argument to the pre-request callback you set up with CURLOPT_PREREQFUNCTION(3). That's it. That's the whole job. Iconic, honestly. π
Basically it's your lil' bag of snacks you drop off before the callback shows up, and the callback gets to open it. No cap.
π DEFAULT π
NULL
(which is giving "no snacks were packed" energy, ngl π)
π¦ PROTOCOLS π¦
this functionality affects all supported protocols β like, every single one, fr fr π
π₯ EXAMPLE π₯
struct priv {
void *custom;
};
static int prereq_callback(void *clientp,
char *conn_primary_ip,
char *conn_local_ip,
int conn_primary_port,
int conn_local_port)
{
printf("Connection made to %s:%d\n", conn_primary_ip, conn_primary_port);
return CURL_PREREQFUNC_OK;
}
int main(void)
{
struct priv prereq_data;
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_PREREQFUNCTION, prereq_callback);
curl_easy_setopt(curl, CURLOPT_PREREQDATA, &prereq_data);
curl_easy_perform(curl);
}
}
see how &prereq_data gets handed over and then just... shows up as clientp in the callback? that's the whole trick, bestie πͺ
β AVAILABILITY β
added in curl 7.80.0 β so if you're on something older, this is not the moment, sorry π
π· RETURN VALUE π·
curl_easy_setopt(3) hands you back a CURLcode β it's telling you whether it ate or whether it choked π
CURLE_OK(0) β everything was OK, slay β- non-zero β an error occurred, go check
libcurl-errors(3), iykyk
π SEE ALSO π
β οΈ heads up: this is the data half of the pair. the actual callback comes from CURLOPT_PREREQFUNCTION(3) β that's where the action lives. this option is just the plus-one π«Ά
and that's the page!! mwah π β brought to you by libcurl, dated 2026-10-12, in the one and only CURLOPT_PREREQDATA(3) era. go forth and pass pointers, bestie ππ¦π
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms