cURL / Mailing Lists / curl-library / Single Mail


Sharing of cookies between easy handles

From: Dmitriy Sergeyev <>
Date: Sat, 23 Aug 2008 21:13:32 +0700


I'm using libcurl 7.18.2 and have faced with problem of sharing cookies
between easy handles, using them with multi-interface.
The brief sequence of actions my routines perform is the following:


share = curl_share_init();
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE |

multi = curl_multi_init();

// The FIRST request setup
easy1 = curl_easy_init();
curl_easy_setopt(easy1, CURLOPT_SHARE, share);
curl_easy_setopt(easy1, CURLOPT_URL, "http://somehost/login");
curl_easy_setopt(easy1, CURLOPT_WRITEFUNCTION, ...);
curl_easy_setopt(easy1, CURLOPT_WRITEDATA, ...);

curl_multi_add_handle(multi, easy1);

// Here comes the loop for multi handle to perform the FIRST request until

curl_multi_remove_handle(multi, easy1);

// The SECOND request setup (almost the same, but lets describe)
easy2 = curl_easy_init();
curl_easy_setopt(easy2, CURLOPT_SHARE, share);
curl_easy_setopt(easy2, CURLOPT_URL, "http://somehost/perform");
curl_easy_setopt(easy2, CURLOPT_WRITEFUNCTION, ...);
curl_easy_setopt(easy2, CURLOPT_WRITEDATA, ...);

curl_multi_add_handle(multi, easy2);

// Here comes the loop for multi handle to perform the SECOND request until

curl_multi_remove_handle(multi, easy2);

The FIRST request, as you can see, does some "login" (just for your
information) and the response to this request contains "Set-Cookie" header
with authentication data. The SECOND request performs some action and it
requires this authentication data to be specified in "Cookie".

The libcurl documentation sais: "If you add a share that is set to share
cookies, your easy handle will use that cookie cache and get the cookie
engine enabled." Thus I'm expecting libcurl to automatically
process/store/receive cookies. And reading several posts in this mailing
list, it seems that it should be like this. But the SECOND request doesn't
contain any "Cookie" headers. :(

The pseudo code I provided is the only resulting sequence of actions
performed in single thread by my curl-wrapper component. It quite bulky so I
suppose you don't like to see it. But if you wish, I could implement
standalone mini sample, which does the same. However just want to ensure
first, that the sequence is correct and it really should done what I'm

Best regards,
Dmitriy Sergeyev, C++ Developer
of ISS Art, Ltd., Omsk, Russia
Received on 2008-08-23