• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLINFO_COOKIELIST
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_COOKIELIST (3)
9  - curl_easy_getinfo (3)
10  - curl_easy_setopt (3)
11---
12
13# NAME
14
15CURLINFO_COOKIELIST - get all known cookies
16
17# SYNOPSIS
18
19~~~c
20#include <curl/curl.h>
21
22CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_COOKIELIST,
23                           struct curl_slist **cookies);
24~~~
25
26# DESCRIPTION
27
28Pass a pointer to a 'struct curl_slist *' to receive a linked-list of all
29cookies curl knows (expired ones, too). Do not forget to call
30curl_slist_free_all(3) on the list after it has been used. If there are no
31cookies (cookies for the handle have not been enabled or simply none have been
32received) the 'struct curl_slist *' is made a NULL pointer.
33
34Since 7.43.0 cookies that were imported in the Set-Cookie format without a
35domain name are not exported by this option.
36
37# PROTOCOLS
38
39HTTP(S)
40
41# EXAMPLE
42
43~~~c
44int main(void)
45{
46  CURL *curl = curl_easy_init();
47  if(curl) {
48    CURLcode res;
49    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
50
51    /* enable the cookie engine */
52    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
53
54    res = curl_easy_perform(curl);
55
56    if(!res) {
57      /* extract all known cookies */
58      struct curl_slist *cookies = NULL;
59      res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
60      if(!res && cookies) {
61        /* a linked list of cookies in cookie file format */
62        struct curl_slist *each = cookies;
63        while(each) {
64          printf("%s\n", each->data);
65          each = each->next;
66        }
67        /* we must free these cookies when we are done */
68        curl_slist_free_all(cookies);
69      }
70    }
71    curl_easy_cleanup(curl);
72  }
73}
74~~~
75
76# AVAILABILITY
77
78Added in 7.14.1
79
80# RETURN VALUE
81
82Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
83