GNURLOPT_COOKIEJAR(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

okay so we're deep in the gnurl manual, specifically the curl_easy_setopt options section, and this page is GNURLOPT_COOKIEJAR(3). bestie, this is the one that says where your cookies go when the handle gets cleaned up. no cap. πŸ’…


✨ NAME ✨

CURLOPT_COOKIEJAR β€” file name to store cookies to. that's it, that's the vibe. πŸͺ


✨ SYNOPSIS ✨

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIEJAR, char
       *filename);

πŸ’… DESCRIPTION πŸ’…

okay so you pass a filename as char *, null-terminated. this makes libcurl write all internally known cookies to the specified file when curl_easy_cleanup(3) is called. if no cookies are known, no file will be created. periodt.

specify "-" as filename to instead have the cookies written to stdout. using this option also enables cookies for this session, so if you for example follow a location it will make matching cookies get sent accordingly. it's giving cookie-session energy. πŸͺ✨

not me needing to say this twice: libcurl doesn't read any cookies from the cookie jar. if you want to read cookies from a file, use CURLOPT_COOKIEFILE(3). iykyk.

if the cookie jar file can't be created or written to (when curl_easy_cleanup(3) is called), libcurl will not and cannot report an error for this. using CURLOPT_VERBOSE(3) or CURLOPT_DEBUGFUNCTION(3) will get a warning to display, but that is the only visible feedback you get about this possibly lethal situation. possibly lethal, bestie. 😭

since 7.43.0 cookies that were imported in the Set-Cookie format without a domain name are not exported by this option.

the application does not have to keep the string around after setting this option. you can let that string go, live your life. πŸ¦‹


🌸 DEFAULT 🌸

NULL


πŸ¦‹ PROTOCOLS πŸ¦‹

HTTP


πŸ“ EXAMPLE πŸ“

CURL *curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/foo.bin");

  /* export cookies to this file when closing the handle */
  curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "/tmp/cookies.txt");

  ret = curl_easy_perform(curl);

  /* close the handle, write the cookies! */
  curl_easy_cleanup(curl);
}

the way that curl_easy_cleanup(curl) is the main character of cookie-writing... obsessed. πŸ”₯


🌈 AVAILABILITY 🌈

Along with HTTP


⭐ RETURN VALUE ⭐

returns CURLE_OK if HTTP is supported, CURLE_UNKNOWN_OPTION if not, or CURLE_OUT_OF_MEMORY if there was insufficient heap space. slay. βœ…


πŸ‘‘ SEE ALSO πŸ‘‘

CURLOPT_COOKIEFILE(3), CURLOPT_COOKIE(3), CURLOPT_COOKIELIST(3), β€” yes, that trailing comma is literally there, i'm keeping it. πŸ’–


okay bestie that's the whole page: this was libcurl 7.37.0, dated 17 Jun 2014, and it's serving GNURLOPT_COOKIEJAR(3) energy from the gnurl manual. mwah, go write those cookies. πŸŽ€βœ¨πŸ’…

πŸ“¦ where this page comes from