curl-library
Relation between CURLOPT_SHARE and cookie handling
Date: Thu, 13 Nov 2003 22:11:20 +0530
Hi,
The code I am running is almost in sync with the curl cvs. To handle cookies I was only using some of curl's helper functions but was setting cookie directly in the Headers. Every thing seem to work fine till I tried to do the following:
m_Curlshare = curl_share_init();
curl_share_setopt(m_Curlshare,CURLSHOPT_SHARE,CURL_LOCK_DATA_DNS);
curl_share_setopt(m_Curlshare,CURLSHOPT_LOCKFUNC,dns_curl_lock_function);
curl_share_setopt(m_Curlshare,CURLSHOPT_UNLOCKFUNC,dns_curl_unlock_function);
curl_share_setopt(m_Curlshare,CURLSHOPT_USERDATA, &m_csCurlDNS);
.
.
.
void *curlhandle = curl_easy_init();
curl_easy_setopt(curlhandle, CURLOPT_CONNECTTIMEOUT, m_lTimeout);
curl_easy_setopt(curlhandle, CURLOPT_TIMEOUT, m_lOverallTimeout);
curl_easy_setopt(curlhandle, CURLOPT_FILETIME, (long)true);
curl_easy_setopt(curlhandle, CURLOPT_SHARE, m_Curlshare);
The last call results in data->cookies being initialised. And this results in curl parsing cookies and setting them.
And while we are sending more requests in http.c Curl_http(), when we do the following things:
First we do check if someone has already set Cookie header even if data->set.cookie might be true.
if(data->set.cookie && !checkheaders(data, "Cookie:")) {
if(conn->allocptr.cookie)
free(conn->allocptr.cookie);
conn->allocptr.cookie = aprintf("Cookie: %s\015\012", data->set.cookie);
}
Then we again try and get the cookie list:
if(data->cookies) {
Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
co = Curl_cookie_getlist(data->cookies,
conn->allocptr.cookiehost?
conn->allocptr.cookiehost:host, ppath,
(bool)(conn->protocol&PROT_HTTPS?TRUE:FALSE));
Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
}
But this time we don't check using checkheaders?
if(co) {
int count=0;
struct Cookie *store=co;
/* now loop through all cookies that matched */
while(co) {
if(co->value) {
if(0 == count) {
add_bufferf(req_buffer, "Cookie: ");
}
add_bufferf(req_buffer,
"%s%s=%s", count?"; ":"", co->name, co->value);
count++;
}
co = co->next; /* next cookie please */
}
if(count) {
add_buffer(req_buffer, "\r\n", 2);
}
Curl_cookie_freelist(store); /* free the cookie list */
co=NULL;
}
Why is that?
My problem is that because I am setting the cookie header explicitly outside of curl and still want to use the share option, how do I stop curl from automatically sending cookies? Most of the sites don't mind duplicate cookies being sent in the same request but some don't work.
Thanks,
Siddhartha.
-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/
Received on 2003-11-13