cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Redirect & cookie

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 21 Mar 2002 13:18:14 +0100 (MET)

On Thu, 21 Mar 2002, Jacky Lam wrote:

> I have two problems on using cookie.
>
> First is that, my program is a multi-thread download program. Each
> for them may learn new cookies upon downloading. But they need to share the
> cookie information. However, if I use CURL_SETOPT_COOKIEJAR to store the
> cookies for different threads, the cookie files will be corrupted (some new
> cookies will be overwritten by old one). Is there any clever way to
> overcome this problem?

Yes, use different files. ;-)

We've been discussing the issues of how to be able to use ONE single cookie
jar for multiple easy handles and you're welcome to submit your ideas and
suggestions on how we should proceed to make this reality.

The first step should be to introduce proper mutex callbacks (as Noel Byron
posted about earlier today), then we need a defined way to tell separate easy
handles how to share data between them. Data could include cookies,
connections, SSL session IDs and more.

Until that works, you can store the files separately and then "merge" them
yourself before passing them on as input to the following requests.

> Second, I try to solve the above program by using a shared structure
> to store my cookie. So, I need to use CURL_SETOPT_COOKIE to set my cookie
> on each request. However, if the cookie is learnt from a HTTP redirent
> response and I have used CURL_SETOPT_FOLLOWLOCATION, it seems that the
> library doesn't have any mean for me to set cookie for the redirected
> request. Besides, I handle the redirection by myself, is there any way to
> do that easily?

The problem with CURL_SETOPT_COOKIE is that is simply sets a header to
include in the (first) request. It does not add a cookie to the internal
cookie jar.

The only way to do that with the current interface is to read cookie headers
or a cookie jar from a file.

Thus, you need to create such a file and have libcurl read it.

Again, I'm all ears for suggestions on how this can be improved in future
releases.

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2002-03-21