cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Redirect & cookie

From: Jacky Lam <sylam_at_emsoftltd.com>
Date: Thu, 21 Mar 2002 23:30:22 +0800

----- Original Message -----
From: "Daniel Stenberg" <daniel_at_haxx.se>
To: "Jacky Lam" <sylam_at_emsoftltd.com>
Cc: "libcurl Mailing list" <curl-library_at_lists.sourceforge.net>
Sent: Thursday, March 21, 2002 8:18 PM
Subject: Re: Redirect & cookie

> 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.
>
    Yes, I also think about using separate files. However, managing
cookies(merging, eliminating,....) with text file operations is too trouble
and the overhead is too high. So, I am now creating a global cookie list in
memory using the library functions directly. Although I am not testing it
hardly, it seems work.
    BTW, is the cookie functions in cookie.c MT safe?

> > 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.
>
    However, having a callback funciton upon redirect? Also, an alternative
to store cookies in memory is useful.

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