Re: HTTP::Cookies::Netscape->save()

Jeremy D. Impson (jdimpson@source.syr.edu)
Sat, 20 Feb 1999 16:15:05 -0500 (EST)


On 18 Feb 1999, Gisle Aas wrote:


[snip] 

> > HTTP::Cookies::Netscape->save() uses a
> > special callback subroutine that prints out to the cookie file in
> > Netscape's format.  However, there is one line that goes: 
> > 
> > 	return if $now > $expires;
> > 
> > resulting in the cookie not being written to the file.

[snip]

> I consider this to be a bug in HTTP::Cookies->save().  I don't object
> to having such an attribute, but I think I would prefer to call it
> something like 'save_expired_cookies'.

Currently, HTTP::Cookies->save() simple calls HTTP::Cookies->as_string,
and writes out the return string to the cookie file.  (It calls
as_string(!$self->{ignore_discard}), telling as_string to even write out
discarded cookies if the user wants).

This is the source of the bug, I think.  It makes sense of as_string to
print _all_ cookies in the object's cache, but doesn't make sense to write
them out.  

I could slip a line similar to 

	return if $now > $expires and !$self->{save_expired_cookies'};

so that as_string returns nothing if the cookie has expired.  But I'm not
sure that this wouldn't be confusing to the programmer, expecting to see
the cookie regardless of whether it is expired.

I could make a second argument to as_string, so that the user can specify
"show all cookies we have cached, even expired ones".  Then the behaviour
would be explicitly documented.

Or, I could set a flag so as_string() knows it is being called by save() 
and will not write out the expired cookie (but will when called by the
user).  

Opinions?  I like the first one, but I don't want to gratuitously change
interfaces.  Or behaviours, which would happen because now all of a sudden
HTTP::Cookies->as_string() doesn't return expired cookies unless
explicitly told to.  


> > (Now I just have to figure out how to get Netscape to reload the cookie
> > file without having to restart it.)
> 
> Hack Mozilla source code maybe?

Indeed.  I have some evidence that Netscape 4.0X will re-read its cookie
file everytime a new window is opened.  I have yet to fully investigate. 

--Jeremy

---------------------------------------------------------------------------
Jeremy Impson                               Linux, Perl, and Network geek
jdimpson@source.syr.edu                     http://source.syr.edu/~jdimpson