CURLOPT_COOKIELIST.3 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_COOKIELIST 3 "19 Jun 2014" libcurl libcurl
  26. .SH NAME
  27. CURLOPT_COOKIELIST \- add to or manipulate cookies held in memory
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIELIST,
  32. char *cookie);
  33. .SH DESCRIPTION
  34. Pass a char * to a \fIcookie\fP string.
  35. Such a cookie can be either a single line in Netscape / Mozilla format or just
  36. regular HTTP-style header (Set-Cookie: ...) format. This will also enable the
  37. cookie engine. This adds that single cookie to the internal cookie store.
  38. Exercise caution if you are using this option and multiple transfers may occur.
  39. If you use the Set-Cookie format and do not specify a domain then the cookie is
  40. sent for any domain (even after redirects are followed) and cannot be modified
  41. by a server-set cookie. If a server sets a cookie of the same name (or maybe
  42. you have imported one) then both will be sent on a future transfer to that
  43. server, likely not what you intended. To address these issues set a domain in
  44. Set-Cookie (doing that will include sub-domains) or use the Netscape format as
  45. shown in EXAMPLE.
  46. Additionally, there are commands available that perform actions if you pass in
  47. these exact strings:
  48. .IP ALL
  49. erases all cookies held in memory
  50. .IP SESS
  51. erases all session cookies held in memory
  52. .IP FLUSH
  53. writes all known cookies to the file specified by \fICURLOPT_COOKIEJAR(3)\fP
  54. .IP RELOAD
  55. loads all cookies from the files specified by \fICURLOPT_COOKIEFILE(3)\fP
  56. .SH DEFAULT
  57. NULL
  58. .SH PROTOCOLS
  59. HTTP
  60. .SH EXAMPLE
  61. .nf
  62. /* This example shows an inline import of a cookie in Netscape format.
  63. You can set the cookie as HttpOnly to prevent XSS attacks by prepending
  64. #HttpOnly_ to the hostname. That may be useful if the cookie will later
  65. be imported by a browser.
  66. */
  67. #define SEP "\\t" /* Tab separates the fields */
  68. char *my_cookie =
  69. "example.com" /* Hostname */
  70. SEP "FALSE" /* Include subdomains */
  71. SEP "/" /* Path */
  72. SEP "FALSE" /* Secure */
  73. SEP "0" /* Expiry in epoch time format. 0 == Session */
  74. SEP "foo" /* Name */
  75. SEP "bar"; /* Value */
  76. /* my_cookie is imported immediately via CURLOPT_COOKIELIST.
  77. */
  78. curl_easy_setopt(curl, CURLOPT_COOKIELIST, my_cookie);
  79. /* The list of cookies in cookies.txt will not be imported until right
  80. before a transfer is performed. Cookies in the list that have the same
  81. hostname, path and name as in my_cookie are skipped. That is because
  82. libcurl has already imported my_cookie and it's considered a "live"
  83. cookie. A live cookie will not be replaced by one read from a file.
  84. */
  85. curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookies.txt"); /* import */
  86. /* Cookies are exported after curl_easy_cleanup is called. The server
  87. may have added, deleted or modified cookies by then. The cookies that
  88. were skipped on import are not exported.
  89. */
  90. curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt"); /* export */
  91. curl_easy_perform(curl); /* cookies imported from cookies.txt */
  92. curl_easy_cleanup(curl); /* cookies exported to cookies.txt */
  93. .fi
  94. .SH "Cookie file format"
  95. The cookie file format and general cookie concepts in curl are described
  96. online here: https://curl.se/docs/http-cookies.html
  97. .SH AVAILABILITY
  98. \fBALL\fP was added in 7.14.1
  99. \fBSESS\fP was added in 7.15.4
  100. \fBFLUSH\fP was added in 7.17.1
  101. \fBRELOAD\fP was added in 7.39.0
  102. .SH RETURN VALUE
  103. Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
  104. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  105. .SH "SEE ALSO"
  106. .BR CURLOPT_COOKIEFILE "(3), " CURLOPT_COOKIEJAR "(3), " CURLOPT_COOKIE "(3), "
  107. .BR CURLINFO_COOKIELIST "(3), "