Indy 9
|
TIdCookieManager = class(TIdBaseComponent)
The TIdCookieManager component provides the Add and Add2 methods that enable maintenance of Cookie class instances added to the CookieCollection in an HTTP Client connection. The GenerateCookieList method is provided to create a textual representation of Cookies maintained for a specific URI.
In addition, TIdCookieManager implements event handlers that allow event notifications during creation or destruction of the TIdCookieManager class instance, and when Cookies are added using the Cookie manager.
TIdCookieManager is used by a TIdHTTP client in the CookieMananger property when AllowCookies is True. The HTTP client uses CookieManager to maintain a Cookie collection when 'Set-cookie' or 'Set-cookie2' headers are detected in a response from an HTTP server.
property CookieCollection: TIdCookies;
Use the OnNewCookie event handler to manage the CookieCollection when new Cookie class instances are created in AddCookie or AddCookie2.
Use the OnCreate and OnDestroy event handlers to manage the CookieCollection during creation or destruction of the TIdCookieManager class instance.
property OnCreate: TOnCreateEvent;
Applications must assign a procedure to the event handler to allow responding to the event notification.
Use OnDestroy to handle management of the CookieCollection when the object instance is freed.
property OnDestroy: TOnDestroyEvent;
Applications must assign a procedure to the event handler to allow responding to the event notification.
Use OnCreate to handle management of the CookieCollection when the object instance is created.
procedure AddCookie(ACookie: String; AHost: String);
AddCookie checks that the Cookie is valid for the Domain specified in AHost prior to signalling the OnNewCookie event handler. When AHost is not a valid Domain, or the OnNewCookie event handler indicates that the Cookie has been rejected, the Cookie class instance is removed from the CookieCollection and freed.
procedure AddCookie2(ACookie: String; AHost: String);
AddCookie2 checks that the Cookie is valid for the Domain specified in AHost prior to signalling the OnNewCookie event handler. When AHost is not a valid Domain, or the OnNewCookie event handler indicates that the Cookie has been rejected, the Cookie class instance is removed from the CookieCollection and freed.
constructor Create(AOwner: TComponent); override;
Calling Create will signal a TNotifyEvent when a procedure has been assigned to the OnCreate event handler. Use OnCreate to handle management of the CookieCollection during creation of the TIdCookieManager object instance.
destructor Destroy; override;
Destroy frees resources allocated in the Create method, including the CookieCollection property, prior to calling the inherited Destroy method.
function GenerateCookieList(URL: TIdURI; SecureConnection: Boolean = false): String;
SecureConnection indicates whether Cookies must contain a Secure attribute value before they are included in the generated Cookie content for the HTTP client.
Cookies in the CookieCollection will not be used in the generated content when Domain, Path, or Secure Cookie attributes do not match the required values. Cookies can also be ignored when they have Expired.
GenerateCookieList creates and populates a TIdCookieList with Cookie class instances matching the required values, and fills the return value with the CookieName and Value for corresponding Cookies in the list. GenerateCookieList frees the TIdCookieList prior to exiting from the method.
GenerateCookieList is called when an HTTP request is prepared and executed using the Post or Put methods of an HTTP client.
property OnNewCookie: TOnNewCookieEvent;
Applications must assign a procedure to the event handler to allow responding to the event notification. OnNewCookie can indicate if the Cookie is accepted or rejected based on values detected in the Cookie content.
Use OnNewCookie to ovreride the default logic used in management of the CookieCollection when Cookies are added to the collection.