You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by John ORourke <jo...@o-rourke.org> on 2005/08/02 13:30:30 UTC
Apache2::Cookie odd return values
(mp 2.0.1, libapreq2-2.06-dev, httpd 2.0.51, Fedora Core 2)
Hi folks,
I've spent 2 days trying simply to read and write cookies! Just before
I pack it in and become a paper boy, can anyone help?
If you haven't time to read below but have some working cookie
read/write freeze/thaw code or URLs I'd be grateful!
It seems I can bake cookies no problem, they're appearing in the browser:
$c_out_val=Apache2::Cookie->freeze($my_hash_ref);
Apache2::Cookie->new( blah blah )->bake();
But I just can't unfreeze them! I've tried the following ways to get my
cookies:
$jar=Apache2::Cookie::Jar->new($r)
$jar=Apache2::Cookie->fetch($r)
(I also tried using APR::Request::Cookie but it seems to be for Apache
experts only, quite a confusing interface)
...but the cookie value is always "cookie_name=cookie_value", and with
some variations I was getting a second cookie, with a blank value and
the name was "cookie_name=cookie_value".
Anyway, even when I strip the "cookie_name=" off the cookie value,
Apache2::Cookie->thaw($value) just returns $value!
Any help gratefully accepted,
John O'Rourke
Re: Apache2::Cookie odd return values
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
John ORourke wrote:
> Right, I've solved my problem with a hack and some RTFSing, but I think
> I've found a bug either in the docs or Apache2::Cookie...
>
> Basically if I read cookies like this:
> $cookie_hash_ref = APR::Request::Apache2->handle($r)->jar();
> it works, I can treat the return as a hash of cookies.
>
> However, if I (following the Apache2::Cookie man page) go:
> $jar=Apache2::Cookie->new($r);
> foreach $name ($jar->cookies()){ blah blah }
> then the names are actually the full baked header value (eg. "name=value")
>
> I have to crack on with my project but I'll leave that one with you.
> Phil, thanks for the pointers and the cookie recipes in the FAQ!
>
> John
>
Likely this change in the API caught you (2.05-dev and up)
Perl API [joes]
Move bake, bake2 to Apache2::Cookie, now requiring
an extra $r argument. Also ""-operator is mapped
to as_string() for Apache2::Cookie; but APR::Request::Cookie
maps it to value().
AND/OR
(2.06-dev and up)
Perl API [joes]
Drop support for Apache2::Cookie::Jar::new's VALUE_CLASS. 2.05-dev broke
that API, and it's not worth trying to fix. People who need that should
use APR::Request::Cookie::Table's cookie_class() API instead.
Re: Apache2::Cookie odd return values
Posted by Joe Schaefer <jo...@sunstarsys.com>.
John ORourke <jo...@o-rourke.org> writes:
> Right, I've solved my problem with a hack and some RTFSing, but I think
> I've found a bug either in the docs or Apache2::Cookie...
>
> Basically if I read cookies like this:
> $cookie_hash_ref = APR::Request::Apache2->handle($r)->jar();
> it works, I can treat the return as a hash of cookies.
>
> However, if I (following the Apache2::Cookie man page) go:
> $jar=Apache2::Cookie->new($r);
> foreach $name ($jar->cookies()){ blah blah }
> then the names are actually the full baked header value (eg. "name=value")
Strangely enough, everything you talk about here is by design.
And it's also why we recommend the new APR::Request:: modules
over Apache2::Cookie and friends, because it's IMO a simpler API.
--
Joe Schaefer
Re: Apache2::Cookie odd return values
Posted by John ORourke <jo...@o-rourke.org>.
Right, I've solved my problem with a hack and some RTFSing, but I think
I've found a bug either in the docs or Apache2::Cookie...
Basically if I read cookies like this:
$cookie_hash_ref = APR::Request::Apache2->handle($r)->jar();
it works, I can treat the return as a hash of cookies.
However, if I (following the Apache2::Cookie man page) go:
$jar=Apache2::Cookie->new($r);
foreach $name ($jar->cookies()){ blah blah }
then the names are actually the full baked header value (eg. "name=value")
I have to crack on with my project but I'll leave that one with you.
Phil, thanks for the pointers and the cookie recipes in the FAQ!
John
Re: Apache2::Cookie odd return values
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Lets move this to apreq-dev (at) httpd.apache.org
** Remember to remove modperl@ from the reply list.
> (mp 2.0.1, libapreq2-2.06-dev, httpd 2.0.51, Fedora Core 2)
Not an issue, but httpd 2.0.54 is out since you're using the rest current :)
> If you haven't time to read below but have some working cookie
> read/write freeze/thaw code or URLs I'd be grateful!
I don't know about freeze/thaw, but I wrote this FAQ :)
http://perl.apache.org/docs/2.0/user/coding/cooking.html#Sending_Cookies_Using_libapreq2
> (I also tried using APR::Request::Cookie but it seems to be for Apache
> experts only, quite a confusing interface)
HA, I know you're not calling me an apache expert :)
> Any help gratefully accepted,
HTH
Re: Apache2::Cookie odd return values
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Lets move this to apreq-dev (at) httpd.apache.org
** Remember to remove modperl@ from the reply list.
> (mp 2.0.1, libapreq2-2.06-dev, httpd 2.0.51, Fedora Core 2)
Not an issue, but httpd 2.0.54 is out since you're using the rest current :)
> If you haven't time to read below but have some working cookie
> read/write freeze/thaw code or URLs I'd be grateful!
I don't know about freeze/thaw, but I wrote this FAQ :)
http://perl.apache.org/docs/2.0/user/coding/cooking.html#Sending_Cookies_Using_libapreq2
> (I also tried using APR::Request::Cookie but it seems to be for Apache
> experts only, quite a confusing interface)
HA, I know you're not calling me an apache expert :)
> Any help gratefully accepted,
HTH