curl_easy_setopt(3)

๐Ÿ’… NAME ๐Ÿ’…

okay so bestie, welcome to curl_easy_setopt(3) from the Library Functions Manual โ€” the iconic function for setting options for a curl easy handle. ๐Ÿ’–

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLoption option, parameter);

๐ŸŒธ DESCRIPTION ๐ŸŒธ

curl_easy_setopt(3) is literally how you tell libcurl how to behave. โœจ By setting the appropriate options, the application can change libcurl's behavior. All options are set with an option followed by a parameter. That parameter can be a long, a function pointer, an object pointer or a curl_off_t, depending on what the specific option expects.

โš ๏ธ bestie, read this manual carefully โ€” bad input values may cause libcurl to behave badly. ๐Ÿ˜ญ

You can only set one option in each function call. A typical application uses many curl_easy_setopt(3) calls in the setup phase.

The handle argument is the return code from a curl_easy_init(3) or curl_easy_duphandle(3) call.

Options set with this function call are sticky. They remain set for all forthcoming transfers performed using this handle. The options are not in any way reset between transfers, so if you want subsequent transfers with different options, you must change them between the transfers. You can optionally reset all options back to internal default with curl_easy_reset(3).

The order in which the options are set does not matter. periodt. ๐ŸŒˆ


๐ŸŽ€ STRINGS ๐ŸŽ€

Strings passed to libcurl as 'char *' arguments are copied by the library; the string storage associated to the pointer argument may be discarded or reused after curl_easy_setopt(3) returns. The only exception to this rule is really CURLOPT_POSTFIELDS(3), but the alternative that copies the string CURLOPT_COPYPOSTFIELDS(3) has some usage characteristics you need to read up on. ๐Ÿ‘€

This function does not accept input strings longer than CURL_MAX_INPUT_LENGTH (8 MB).

libcurl does little to no verification of the contents of provided strings. Passing in "creative octets" like newlines where they are not expected might trigger unexpected results. ๐Ÿ’€

Before version 7.17.0, strings were not copied. Instead the user was forced keep them available until libcurl no longer needed them.


โœจ OPTIONS โœจ

okay continuing the list, bestie โ€” we're in the H's now and it keeps going forever, but that's literally the point ๐Ÿ’–

and likeโ€ฆ we're not even done yet, there's more list coming, don't go anywhere ๐Ÿซถโœจ





๐ŸŒˆ PROTOCOLS ๐ŸŒˆ

Okay so this functionality? It affects all supported protocols. Every single one. No gatekeeping. ๐Ÿ’…


๐Ÿ’ป EXAMPLE ๐Ÿ’ป

Like, here's the tiniest possible main character program ever:

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

๐Ÿ•ฐ๏ธ AVAILABILITY ๐Ÿ•ฐ๏ธ

Added in curl 7.1 โ€” like, ancient. A true elder. Respect her. ๐Ÿงš


๐Ÿšฆ RETURN VALUE ๐Ÿšฆ

This function hands you back a CURLcode that tells you whether it ate or flopped. ๐Ÿ“

CURLE_OK (0) means everything was literally fine. Anything non-zero means an error happened โ€” check libcurl-errors(3) for the full tea. And ngl, if you set CURLOPT_ERRORBUFFER(3) with curl_easy_setopt(3), there can be an error message chilling in that error buffer when a non-zero comes back. Bestie, that buffer is your friend. ๐Ÿ˜ญ

Strings you pass to libcurl must be shorter than 8000000 bytes, otherwise curl_easy_setopt(3) returns CURLE_BAD_FUNCTION_ARGUMENT (added in 7.65.0). No cap, it will not just vibe through that.

CURLE_BAD_FUNCTION_ARGUMENT also shows up when the argument to an option is invalid โ€” like, say, out of range. Invalid looks bad on you, so don't do it. ๐Ÿ’€

And if you try to set an option that libcurl straight up does not know about โ€” maybe the library is too old to support it, or maybe the option got removed in a recent version โ€” this function returns CURLE_UNKNOWN_OPTION. If support for the option was disabled at compile-time, you get CURLE_NOT_BUILT_IN instead. Two different moods, two different codes. ๐Ÿ™ˆ


๐Ÿซถ SEE ALSO ๐Ÿซถ


โœจ And that's the whole page, bestie! This one came from the libcurl source, version date 2026-10-12, and it's the manual page for curl_easy_setopt(3). Go forth and set some options. Mwah. ๐Ÿ’œ๐ŸŽ€๐Ÿ’…
๐Ÿ“ฆ where this page comes from