Add cookies to shared list

Giganews Newsgroups
Subject: Add cookies to shared list
Posted by:  dk_sz (dk_…@hotmail.com)
Date: Thu, 16 Oct 2008

Hi,

For some reason, I simply can't get this right
without error popping up in some websites.

Each HTTP instance is running in own thread
with own default Indy Cookie handler...

Then in OnNewCookie they merge the new cookie into
shared cookiemanager *FOptions.AllowCookieManager*:

  VAccept := True;
  FOptions.AllowCookieCS.Acquire;
  try
    C := FOptions.AllowCookieManager.CookieCollection.Add;
    C.Assign(ACookie);
    FOptions.AllowCookieManager.CookieCollection.AddCookie(C);
  except
    on E: Exception do
      FOptions.OnExceptionHandler(Self, E);
  end;
  FOptions.AllowCookieCS.Release;

Before a HTTP request is made, I update
the local cookie manager in the HTTP:

  AOptions.AllowCookieCS.Acquire;
  ACookieManagerUpdate.CookieCollection.Assign(FOptions.AllowCookieManager.CookieCollection);
  E := ACookieManagerUpdate.CookieCollection.Count - 1;
  for I := 0 to E do
  begin
    C := ACookieManagerUpdate.CookieCollection[I];
    ACookieManagerUpdate.CookieCollection.AddCookie(C);
  end;
  FOptions.AllowCookieCS.Release;

This however causes access violations.
How is cookies supposed to work in Indy?

From example above can be seen that
FOptions.AllowCookieManager
is my shared cookie list

best regards
Thomas Schulz

Replies