GNURLOPT_COOKIE(3)
π GNURLOPT_COOKIE(3) β the curl_easy_setopt options glow-up πͺ
okay bestie, so this one is a curl_easy_setopt option page from the gnurl/curl family, and it's literally all about handing curl a cookie to shove into your HTTP request. no cap, it's simpler than it sounds. let's get into it π«Ά
β¨ NAME β¨
CURLOPT_COOKIE β set contents of HTTP Cookie header πͺ
πΈ SYNOPSIS πΈ
#include <gnurl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIE, char *cookie);
π DESCRIPTION π
So you pass a pointer to a null-terminated string as the parameter, and that string is what gets used to set a cookie in the HTTP request. the format is supposed to be NAME=CONTENTS, where NAME is the cookie name and CONTENTS is, well, what the cookie contains. slay, that's it π
if you need multiple cookies, you don't set the option a bunch of times β you set them all with a single option, concatenated like this:
"name1=content1; name2=content2;"
etc, etc. group chat energy, all in one message β¨
this option sets the cookie header explicitly in the outgoing request(s). and if multiple requests happen because of authentication, followed redirections, or similar stuff, they will all get this cookie passed on. iconic, honestly.
β οΈ heads up: the cookies set by this option are totally separate from the internal cookie storage held by the cookie engine, and the cookie engine will not modify them. so if you enable the cookie engine and either you've imported a cookie with the same name (like'foo') or the server has set one, that has no effect on the cookies you set here. a request to the server will send both the'foo'held by the cookie engine and the'foo'held by this option. two foos, one request, chaos π
if you want to set a cookie that's instead held by the cookie engine and can be modified by the server, use CURLOPT_COOKIELIST(3) instead. iykyk π§
also: using this option multiple times will only make the latest string override the previous ones. last one wins, periodt.
and no, this option will not enable the cookie engine. if you want parsing and sending cookies automatically, use CURLOPT_COOKIEFILE(3) or CURLOPT_COOKIEJAR(3). that's where the automatic magic lives β¨
good news though β the application does not have to keep the string around after setting this option. curl's got it, you can let it go π¦
π DEFAULT π
NULL, no cookies. as in, no cookies by default. tragic, i know π
π PROTOCOLS π
HTTP (that's the one, that's the vibe)
β EXAMPLE β
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
curl_easy_setopt(curl, CURLOPT_COOKIE, "tool=curl; fun=yes;");
curl_easy_perform(curl);
}
look at that. tool=curl; fun=yes; β two cookies, one option, absolutely ate π₯
π¦ AVAILABILITY π¦
if HTTP is enabled π
π RETURN VALUE π
- Returns
CURLE_OKif HTTP is enabled π CURLE_UNKNOWN_OPTIONif not π- or
CURLE_OUT_OF_MEMORYif there was insufficient heap space π
πΈ SEE ALSO πΈ
k that's the whole page bestie, you're officially a cookie header girlie now πͺπ
this little beauty is from libcurl 7.37.0, dated 17 Jun 2014 β vintage but still serving β¨ mwah, see you in the next manpage π«Ά
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2020, 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