cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Sharing cookies file (CURLOPT_COOKIEJAR+CURLOPT_COOKIEFILE) between processes

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sat, 15 Nov 2014 00:15:40 +0100 (CET)

On Fri, 14 Nov 2014, GLAYAL, Laurent wrote:

> I' using libcurl (7.34.0) and CURLOPT_COOKIEJAR and CURLOPT_COOKIFILE to
> read/store cookies to a file. I have a bunch of questions on using libcurl
> sharing the same cookies file.

They really don't share files at all. They share the cookie jar kept in
memory.

> My first questions are about the concept of 'browser session' when using
> libcurl : Does libcurl store cookies without 'expires' direction in the
> cookies file ?

Yes.

> Such cookies are supposed to expire at browser' session end, but when does a
> 'session' end when using libcurl ?

You decide! Set CURLOPT_COOKIESESSION to 1 and libcurl will consider the next
transfer as the start of a new session and all "session cookies" will be
ignored when loaded.

> My second question is about cookies file locking in the same and between
> processes : I would like to share cookies file between parallel requests not
> only in the same process but between processes, I've found no flock() in
> libcurl code to share cookie file between processes, is it possible to use a
> callback over curl_easy API to manage this file lock everytime a handle is
> trying to load or store data to this file ?

No, there's no locking at all and there's no such callback for file locking.
You are probably better off by doing the locking yourself, extracting cookies
with CURLINFO_COOKIELIST and saving to the file in your application instead of
letting libcurl write to the file.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2014-11-15