gnurl_easy_setopt(3)

๐Ÿ“ฆ version 7.72.0, in nixos 26.05, nixpkgs unstable

๐ŸŽ€ gnurl_easy_setopt(3) โ€” libgnurl Manual ๐ŸŽ€

okay bestie, buckle up โ€” this is the function. everything you're about to read lives in the libgnurl Manual, and it's a long one, so hydrate first ๐Ÿ’–


โœจ NAME โœจ

curl_easy_setopt โ€” the one that sets options for a curl easy handle ๐Ÿซถ


โœจ SYNOPSIS โœจ

#include <gnurl/curl.h>

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

๐Ÿ’… DESCRIPTION ๐Ÿ’…

so curl_easy_setopt(3) is literally the way you tell libcurl how to behave. set the right options and your app gets to change libcurl's whole behavior, no cap. every option gets set with an option followed by a parameter โ€” and that parameter can be a long, a function pointer, an object pointer, or a curl_off_t, depending on what that specific option expects. so likeโ€ฆ read this manual carefully, fr fr, because 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. many. like, a lot. it's giving character development.

options you set with this function call are valid for all forthcoming transfers performed using this handle. and here's the thing โ€” the options are not in any way reset between transfers, so if you want subsequent transfers with different options, you gotta change them between the transfers. you can optionally reset all options back to internal default with curl_easy_reset(3) though, iconic of it โœจ

strings passed to libcurl as 'char *' arguments are copied by the library ๐ŸŽ€ so the string storage associated to the pointer argument may be overwritten 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 ๐Ÿ‘€ (iykyk).

the order in which the options are set does not matter. periodt. ๐Ÿ’…

okay history lesson: before version 7.17.0, strings were not copied. instead the user was forced keep them available until libcurl no longer needed them. so yeah, if you're in your time-travel era, watch out ๐Ÿ•ฐ๏ธ

and the handle โ€” that's the return code from a curl_easy_init(3) or curl_easy_duphandle(3) call. that's your main character. ๐ŸŽ€


๐ŸŒธ BEHAVIOR OPTIONS ๐ŸŒธ


๐ŸŒˆ CALLBACK OPTIONS ๐ŸŒˆ

like, this is the callback era and we're all just living in it ๐Ÿซถ


๐Ÿ˜ญ ERROR OPTIONS ๐Ÿ˜ญ


๐ŸŒ NETWORK OPTIONS ๐ŸŒ


okay that's this chunk done and there is so more coming ๐Ÿ‘€ don't go anywhere bestie ๐Ÿซถ

โœจ NAMES and PASSWORDS OPTIONS (Authentication) โœจ

okay bestie, this whole cluster is about who you are when you knock on the server's door ๐Ÿ”‘ โ€” usernames, passwords, tokens, the works. Every single one links off to its own page, so go deep whenever you need.


๐ŸŒ HTTP OPTIONS

this is the big one, the main character section ๐Ÿ’… โ€” headers, redirects, cookies, HTTP/2 streams, all of it. Settle in.


๐Ÿ“ง SMTP OPTIONS

mail girlies rise ๐Ÿซถ โ€” who's sending, who's receiving, and who's authenticating.

๐Ÿ’€ just so you know, that triple-L spelling (ALLLOWFAILS) is literally how it's spelled in the option name. not a typo of mine, bestie โ€” copy it exactly.

๐Ÿ“ฆ TFTP OPTIONS

tiny but mighty, two options, both iconic in their own lowkey way.


๐Ÿ—‚๏ธ FTP OPTIONS

the vintage queen of protocols and honestly she still serves ๐Ÿ‘‘. Here's every knob.


๐ŸŽฌ RTSP OPTIONS

streaming protocol hours ๐ŸŒˆ โ€” sessions, sequence numbers, and transport headers.


๐Ÿงš PROTOCOL OPTIONS

the general-purpose toolbox โ€” stuff that works across protocols and doesn't want to be boxed in. very main character energy, honestly.

๐Ÿ”Œ CONNECTION OPTIONS ๐Ÿ”Œ

okay so these are the ones that decide like, how your little client actually reaches out and touches the server. connection era ๐Ÿ’…


๐Ÿ” SSL and SECURITY OPTIONS ๐Ÿ”

this whole section is the certified-locked-down-girl era. certs, keys, ciphers, the works โœจ


๐Ÿš SSH OPTIONS ๐Ÿš

for when you're doing the secure-shell thing. keys and known hosts and all that good stuff ๐Ÿ—๏ธ


๐ŸŽ€ OTHER OPTIONS ๐ŸŽ€

the little grab-bag section, love her ๐Ÿ’–


๐Ÿ“Ÿ TELNET OPTIONS ๐Ÿ“Ÿ

one singular option. she's lowkey iconic for standing alone ๐Ÿ˜Œ


๐ŸŒˆ RETURN VALUE ๐ŸŒˆ

CURLE_OK (which is zero) means the option was set properly ๐Ÿ’š. Anything non-zero means an error happened, exactly as <gnurl/curl.h> defines it. Want the full list with descriptions? Go read libcurl-errors(3), it's all laid out there.

๐Ÿšจ Important bestie PSA: any strings you pass in to libcurl must be shorter than 8000000 bytes. If they're not, curl_easy_setopt(3) returns CURLE_BAD_FUNCTION_ARGUMENT (this was added in 7.65.0, so don't come for older versions about it).

If you try to set an option libcurl genuinely doesn't know about โ€” maybe your library is too old to support it, or the option got removed in a recent version โ€” the function returns CURLE_UNKNOWN_OPTION. And if support for that option was disabled at compile-time, it returns CURLE_NOT_BUILT_IN. No cap, those are two different errors ๐Ÿ˜ญ


โœจ EXAMPLE โœจ

the little hello-world of curl, we love to see it:

CURL *curl = curl_easy_init();
if(curl) {
  CURLcode res;
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
  res = curl_easy_perform(curl);
  curl_easy_cleanup(curl);
}

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

go read these next, iykyk:

curl_easy_init(3), curl_easy_cleanup(3), curl_easy_reset(3), curl_easy_getinfo(3), curl_multi_setopt(3)


and that's the whole page, bestie!! ๐ŸŽ€ you just read the entire gnurl_easy_setopt(3) man page โ€” every last option, every last "See ...(3)". this gorgeous thing ships as libcurl 7.38.0, dated 25 Jun 2014, and it lives at gnurl_easy_setopt(3). go forth and set some options ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from