You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by cfaust-dougot <cf...@doyougot.com> on 2006/12/09 13:53:55 UTC

Apache2::Cookie/APR::Request::Cookie

I'm down to the last thing I need to handle without CGI.pm to get rid of it, cookies... But I'm having a problem..
 
I've tried both Apache2::Cookie and APR::Request::Cookie (from the posts I read I got the impression it was better to use ARP::Request::Cookie then Apache2::Cookie).
 
The problem I'm having is the cookie value I'm getting is "cookie_name=cookie_value", pretty much the same thing being talked about here http://www.gossamer-threads.com/lists/modperl/modperl/82277?search_string=APR%3A%3ARequest%3A%3ACookie;#82277
 
Here is how I've tried setting the cookie (seems to be fine)
 
my $packed_cookie = APR::Request::Cookie->new($r->pool,
                 name => 'ISMH_SESSION_ID',
                 value => someval,
                 expires => '+7d',
                 );
$r->err_headers_out->add('Set-Cookie' => $packed_cookie->as_string); 
 
The man page then says to use APR::Request::Cookie I should:
my $jar = $r->jar;
my $cookie = $jar->get("ISMH_SESSION_ID");
 
That results in the error of "Can't call method "get" without a package or object reference"
 
If I use Apache2::Cookie all the way
 my $cookie_req = Apache2::Cookie::Jar->new($r);
 my $cookie = $cookie_req->cookies("ISMH_SESSION_ID");

I get "cookie_name=cookie_value".
I've tried the freeze and thaw methods, but there was no change... I even tried updating libpreq from version 2.07 to 2.08 and there was no change.
 
Am I missing something??
 
Thanks
-Chris

Apache/2.0.55 (Ubuntu) PHP/5.1.6 mod_apreq2-20051231/2.5.7 mod_perl/2.0.2 Perl/v5.8.8 configured

Re: Apache2::Cookie/APR::Request::Cookie

Posted by John ORourke <jo...@o-rourke.org>.
cfaust-dougot wrote:
> I've tried both Apache2::Cookie and APR::Request::Cookie (from the 
> posts I read I got the impression it was better to use 
> ARP::Request::Cookie then Apache2::Cookie).
Definitely.  You also need to read the man pages, but I've saved you the 
trouble...

> $r->err_headers_out->add('Set-Cookie' => $packed_cookie->as_string);
Good - you could also $packed_cookie->bake($r);

> The man page then says to use APR::Request::Cookie I should:
> my $jar = $r->jar;
> my $cookie = $jar->get("ISMH_SESSION_ID");
jar() returns undef if the browser sent no Cookie header - hence "can't 
call get method on undefined".
It's also tied to a hash - $$jar{ISMH_SESSION_ID}

$cookie is an object, which supports the "" overload, but I struggled to 
use that.  The bit you're missing goes after that:

$ismh_session_id = $cookie->value();

Freeze and Thaw are only needed if the cookie value is a data structure 
like a hash, not needed in this case.

hth,
John


RE: Apache2::Cookie/APR::Request::Cookie

Posted by cfaust-dougot <cf...@doyougot.com>.
Does the order matter? 
 
I'm doing this
 
$r->err_headers_out->add( 'Set-Cookie', $cookie->as_string );
$r->headers_out->set( Location => 'http://domain.com/page'); <http://smtp.net.prevare.com/exchweb/bin/redir.asp?URL=http://domain.com/page%27);> 
return Apache2::Const::REDIRECT;
 
I'm guess it doesn't cause when it does work I'm doing
 
$r->err_headers_out->add( 'Set-Cookie', $cookie->as_string );
return Apache2::Const::OK;
 
I don't get it then, I'm using the same exact thing in both the case of the login (post request) and following get request
 
    my $packed_cookie = APR::Request::Cookie->new($r->pool,
                 name  => 'ISMH_SESSION_ID',
                 value  => 'xxx'
                 expires => '+7d',
                 );
    $r->err_headers_out->add('Set-Cookie' => $packed_cookie->as_string);
 
Its never easy :(..
 
Thanks!!

________________________________

From: Clinton Gormley [mailto:clint@traveljury.com]
Sent: Sat 12/9/2006 12:24 PM
To: cfaust-dougot
Cc: modperl@perl.apache.org
Subject: RE: Apache2::Cookie/APR::Request::Cookie




> 
> Can I ask if there is something different when redirecting? It would
> appear the cookie isn't being sent in a redirect.

It should be fine setting cookies in a redirect as long as
1) you're using $r->err_headers_out->add()
2) you're not doing an internal redirect

so, for instance, this sequence:
    $r->headers_out->set( Location => 'http://domain.com/page');
    $r->err_headers_out->add( 'Set-Cookie', $cookie->as_string );
    return Apache2::Const::HTTP_SEE_OTHER;

> 
> When logging in from the post form I see the "Set-Cookie" header being
> set but when I redirect them back to the URl they should be on I don't
> see the "Set-Cookie" header being set even though I pack up the cookie
> and set it again (just like in the previous POST request)

If you're setting the cookie header but you're not seeing it in the
headers from the server, then you're not setting it properly.  Are you
not overwriting the err_headers_out by using ->set instead of ->add?

> 
> But does that even matter? A cookie isn't always set before its read
> in the same session, I might be looking for a cookie that was saved
> the last time you were on the site.

It only matter because it doesn't seem to be working...


clint





RE: Apache2::Cookie/APR::Request::Cookie

Posted by Clinton Gormley <cl...@traveljury.com>.
>  
> Can I ask if there is something different when redirecting? It would
> appear the cookie isn't being sent in a redirect.

It should be fine setting cookies in a redirect as long as 
1) you're using $r->err_headers_out->add()
2) you're not doing an internal redirect

so, for instance, this sequence:
    $r->headers_out->set( Location => 'http://domain.com/page');
    $r->err_headers_out->add( 'Set-Cookie', $cookie->as_string );
    return Apache2::Const::HTTP_SEE_OTHER;

>  
> When logging in from the post form I see the "Set-Cookie" header being
> set but when I redirect them back to the URl they should be on I don't
> see the "Set-Cookie" header being set even though I pack up the cookie
> and set it again (just like in the previous POST request)

If you're setting the cookie header but you're not seeing it in the
headers from the server, then you're not setting it properly.  Are you
not overwriting the err_headers_out by using ->set instead of ->add?

>  
> But does that even matter? A cookie isn't always set before its read
> in the same session, I might be looking for a cookie that was saved
> the last time you were on the site.

It only matter because it doesn't seem to be working...


clint



Re: Apache2::Cookie/APR::Request::Cookie

Posted by Clinton Gormley <cl...@traveljury.com>.
> See these FAQs:
> http://perl.apache.org/docs/2.0/user/coding/cooking.html

Thanks for that Philip - just seen the issue I had in my live code...

And Chris, ignore what I said about add() and set() - I was confused.
> 
> 

________________________________________________________________________

Clinton Gormley clinton@traveljury.com

www.TravelJury.com - For travellers, By travellers




Re: Apache2::Cookie/APR::Request::Cookie

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
cfaust-dougot wrote:
> I have read that and I used to use the 2nd method on that page without 
> any problems.. Because I'm trying to do away with CGI.pm I'm now using 
> the 3rd method "using libapreq2' but without the content type etc when 
> its a redirect.
>  
> Because there isn't a redirect example using libapreq2, does that mean 
> it doesn't work with redirects??
You should be able to use Exapmle #2 replacing CGI::Cookie calls with 
APR:: calls as show in example #3.  Leave th redirect intact.

There is no example because I didn't write one......

It definitely works -- I have production code that does it.


-- 
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/EC88A0BF 0DE5 C55C 6BF3 B235 2DAB  B89E 1324 9B4F EC88 A0BF

I never had a dream come true
'Til the day that I found you.
Even though I pretend that I've moved on
You'll always be my baby.
I never found the words to say
You're the one I think about each day
And I know no matter where life takes me to
A part of me will always be...
A part of me will always be with you.

Re: Apache2::Cookie/APR::Request::Cookie

Posted by John ORourke <jo...@o-rourke.org>.
cfaust-dougot wrote:
> I'm always passing a relitive path to "Location" so I didn't think it 
> would matter.. Sure enough once I simply added 'Path => '/'," to all 
> my cookie create statements, SUCCESS!!!
Yay!  Has to be said I only thought of the hostname because I do the 
path out of habit!

By the way, I found Firefox (v1.x at least) can't cope with (in the raw 
header) path="/" - it requires path=/
(ie. no quotes)  If anyone can explain it I'd love to know.

Here's my baking recipe:

sub bake {
    my ($c, $r) = @_;
    my $val=$c->as_string();
    $val=~s/="\/"/=\//; # firefox hack
    $r->err_headers_out->add("Set-Cookie", $val);
}

cheers
John


RE: Apache2::Cookie/APR::Request::Cookie

Posted by cfaust-dougot <cf...@doyougot.com>.
The path was it!!!!
 
I'm always passing a relitive path to "Location" so I didn't think it would matter.. Sure enough once I simply added 'Path => '/'," to all my cookie create statements, SUCCESS!!!
 
I'm now 100% without CGI.pm in my scripts, WooHoo!!!
 
Thanks John, Clinton and Philip, you guys rock!!
 
-Chris

________________________________

From: John ORourke [mailto:john@versatilia.com]
Sent: Sat 12/9/2006 1:19 PM
To: cfaust-dougot
Cc: modperl@perl.apache.org
Subject: Re: Apache2::Cookie/APR::Request::Cookie


Ummm... this should be obvious but are you redirecting to a different hostname?

In your code you're not explicitly setting the cookie domain or path, so the browser will only send the cookie to pages with the same hostname.  That would explain why you don't see it on the redirect...

Note that a good browser won't allow one domain to set a cookie for another domain too - I've never tested this though.

John

cfaust-dougot wrote: 

	I have read that and I used to use the 2nd method on that page without any problems.. Because I'm trying to do away with CGI.pm I'm now using the 3rd method "using libapreq2' but without the content type etc when its a redirect.
	 
	Because there isn't a redirect example using libapreq2, does that mean it doesn't work with redirects??
	 
	Thanks
	-Chris

________________________________

	From: Philip M. Gollucci [mailto:pgollucci@p6m7g8.com]
	Sent: Sat 12/9/2006 12:26 PM
	To: cfaust-dougot
	Cc: Clinton Gormley; modperl@perl.apache.org
	Subject: Re: Apache2::Cookie/APR::Request::Cookie
	
	

	cfaust-dougot wrote:
	> Thanks Clinton,John and Philip.. Everything is helpful.
	> 
	> Can I ask if there is something different when redirecting? It would
	> appear the cookie isn't being sent in a redirect.
	> 
	> When logging in from the post form I see the "Set-Cookie" header being
	> set but when I redirect them back to the URl they should be on I don't
	> see the "Set-Cookie" header being set even though I pack up the cookie
	> and set it again (just like in the previous POST request)
	> 
	> But does that even matter? A cookie isn't always set before its read in
	> the same session, I might be looking for a cookie that was saved the
	> last time you were on the site.
	See these FAQs:
	http://perl.apache.org/docs/2.0/user/coding/cooking.html
	
	
	
	--
	------------------------------------------------------------------------
	Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
	Consultant / http://p6m7g8.net/Resume/resume.shtml
	Senior Software Engineer - TicketMaster - http://ticketmaster.com <http://ticketmaster.com/> 
	1024D/EC88A0BF 0DE5 C55C 6BF3 B235 2DAB  B89E 1324 9B4F EC88 A0BF
	
	I never had a dream come true
	'Til the day that I found you.
	Even though I pretend that I've moved on
	You'll always be my baby.
	I never found the words to say
	You're the one I think about each day
	And I know no matter where life takes me to
	A part of me will always be...
	A part of me will always be with you.
	



Re: Apache2::Cookie/APR::Request::Cookie

Posted by John ORourke <jo...@versatilia.com>.
Ummm... this should be obvious but are you redirecting to a different 
hostname?

In your code you're not explicitly setting the cookie domain or path, so 
the browser will only send the cookie to pages with the same hostname.  
That would explain why you don't see it on the redirect...

Note that a good browser won't allow one domain to set a cookie for 
another domain too - I've never tested this though.

John

cfaust-dougot wrote:
> I have read that and I used to use the 2nd method on that page without 
> any problems.. Because I'm trying to do away with CGI.pm I'm now using 
> the 3rd method "using libapreq2' but without the content type etc when 
> its a redirect.
>  
> Because there isn't a redirect example using libapreq2, does that mean 
> it doesn't work with redirects??
>  
> Thanks
> -Chris
>
> ------------------------------------------------------------------------
> *From:* Philip M. Gollucci [mailto:pgollucci@p6m7g8.com]
> *Sent:* Sat 12/9/2006 12:26 PM
> *To:* cfaust-dougot
> *Cc:* Clinton Gormley; modperl@perl.apache.org
> *Subject:* Re: Apache2::Cookie/APR::Request::Cookie
>
> cfaust-dougot wrote:
> > Thanks Clinton,John and Philip.. Everything is helpful.
> > 
> > Can I ask if there is something different when redirecting? It would
> > appear the cookie isn't being sent in a redirect.
> > 
> > When logging in from the post form I see the "Set-Cookie" header being
> > set but when I redirect them back to the URl they should be on I don't
> > see the "Set-Cookie" header being set even though I pack up the cookie
> > and set it again (just like in the previous POST request)
> > 
> > But does that even matter? A cookie isn't always set before its read in
> > the same session, I might be looking for a cookie that was saved the
> > last time you were on the site.
> See these FAQs:
> http://perl.apache.org/docs/2.0/user/coding/cooking.html
>
>
>
> --
> ------------------------------------------------------------------------
> Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
> Consultant / http://p6m7g8.net/Resume/resume.shtml
> Senior Software Engineer - TicketMaster - http://ticketmaster.com 
> <http://ticketmaster.com/>
> 1024D/EC88A0BF 0DE5 C55C 6BF3 B235 2DAB  B89E 1324 9B4F EC88 A0BF
>
> I never had a dream come true
> 'Til the day that I found you.
> Even though I pretend that I've moved on
> You'll always be my baby.
> I never found the words to say
> You're the one I think about each day
> And I know no matter where life takes me to
> A part of me will always be...
> A part of me will always be with you.
>


RE: Apache2::Cookie/APR::Request::Cookie

Posted by cfaust-dougot <cf...@doyougot.com>.
I have read that and I used to use the 2nd method on that page without any problems.. Because I'm trying to do away with CGI.pm I'm now using the 3rd method "using libapreq2' but without the content type etc when its a redirect.
 
Because there isn't a redirect example using libapreq2, does that mean it doesn't work with redirects??
 
Thanks
-Chris

________________________________

From: Philip M. Gollucci [mailto:pgollucci@p6m7g8.com]
Sent: Sat 12/9/2006 12:26 PM
To: cfaust-dougot
Cc: Clinton Gormley; modperl@perl.apache.org
Subject: Re: Apache2::Cookie/APR::Request::Cookie



cfaust-dougot wrote:
> Thanks Clinton,John and Philip.. Everything is helpful.
> 
> Can I ask if there is something different when redirecting? It would
> appear the cookie isn't being sent in a redirect.
> 
> When logging in from the post form I see the "Set-Cookie" header being
> set but when I redirect them back to the URl they should be on I don't
> see the "Set-Cookie" header being set even though I pack up the cookie
> and set it again (just like in the previous POST request)
> 
> But does that even matter? A cookie isn't always set before its read in
> the same session, I might be looking for a cookie that was saved the
> last time you were on the site.
See these FAQs:
http://perl.apache.org/docs/2.0/user/coding/cooking.html



--
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com <http://ticketmaster.com/> 
1024D/EC88A0BF 0DE5 C55C 6BF3 B235 2DAB  B89E 1324 9B4F EC88 A0BF

I never had a dream come true
'Til the day that I found you.
Even though I pretend that I've moved on
You'll always be my baby.
I never found the words to say
You're the one I think about each day
And I know no matter where life takes me to
A part of me will always be...
A part of me will always be with you.



Re: Apache2::Cookie/APR::Request::Cookie

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
cfaust-dougot wrote:
> Thanks Clinton,John and Philip.. Everything is helpful.
>  
> Can I ask if there is something different when redirecting? It would 
> appear the cookie isn't being sent in a redirect.
>  
> When logging in from the post form I see the "Set-Cookie" header being 
> set but when I redirect them back to the URl they should be on I don't 
> see the "Set-Cookie" header being set even though I pack up the cookie 
> and set it again (just like in the previous POST request)
>  
> But does that even matter? A cookie isn't always set before its read in 
> the same session, I might be looking for a cookie that was saved the 
> last time you were on the site.
See these FAQs:
http://perl.apache.org/docs/2.0/user/coding/cooking.html



-- 
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/EC88A0BF 0DE5 C55C 6BF3 B235 2DAB  B89E 1324 9B4F EC88 A0BF

I never had a dream come true
'Til the day that I found you.
Even though I pretend that I've moved on
You'll always be my baby.
I never found the words to say
You're the one I think about each day
And I know no matter where life takes me to
A part of me will always be...
A part of me will always be with you.

RE: Apache2::Cookie/APR::Request::Cookie

Posted by cfaust-dougot <cf...@doyougot.com>.
Thanks Clinton,John and Philip.. Everything is helpful.
 
Can I ask if there is something different when redirecting? It would appear the cookie isn't being sent in a redirect.
 
When logging in from the post form I see the "Set-Cookie" header being set but when I redirect them back to the URl they should be on I don't see the "Set-Cookie" header being set even though I pack up the cookie and set it again (just like in the previous POST request)
 
But does that even matter? A cookie isn't always set before its read in the same session, I might be looking for a cookie that was saved the last time you were on the site.
 
Thanks
-Chris

________________________________

From: Clinton Gormley [mailto:clint@traveljury.com]
Sent: Sat 12/9/2006 11:07 AM
To: cfaust-dougot
Cc: modperl@perl.apache.org
Subject: RE: Apache2::Cookie/APR::Request::Cookie




> After the cookie has been set...
> 
> my $req = APR::Request::Apache2->handle( $r );
> my $jar = $req->jar;
> print $req->jar_status();
> 
> Just gives me the error of "Missing Input Data" and I'm sure apreq2 is
> loaded.

from what John said:

> jar() returns undef if the browser sent no Cookie header - hence
> "can't call get method on undefined".

it sounds like your cookie isn't being sent by your browser back to your
web server.  i remember having some problems with the parameters I was
passing to the cookie.  Try just setting name and value and see what
happens there.

Also, check what headers your browser is sending back.  (The LiveHeader
add-on in firefox will do this for you)
> 
> Man, I wish getting rid of CGI.pm was as easy as using it :) - Back to
> the drawing board!!
> 
> Thanks
> -Chris
>
> 
>
> ______________________________________________________________________
> From: Clinton Gormley [mailto:clint@traveljury.com]
> Sent: Sat 12/9/2006 10:00 AM
> To: cfaust-dougot
> Cc: modperl@perl.apache.org
> Subject: RE: Apache2::Cookie/APR::Request::Cookie
>
>
> On Sat, 2006-12-09 at 09:37 -0500, cfaust-dougot wrote:
> > Thanks for the reply Clinton, I was just using the same request obj
> > from the handler, guess that was wrong :)
> >
> > I tried your read example and now I don't get anything at all (even
> > though I can see the cookie on the machine)
>
> What do you mean by 'I can see the cookie on the machine'?
>
> Can you see in the browser that it is being set?
>
>
> >
> >         my $req = APR::Request::Apache2->handle( $r );
> >         my $jar = $req->jar;
>
> Try : print $req->jar_status();
> and see : perldoc APR::Request
>
> >         my %cookies;
> >         foreach my $key ( keys %$jar ) {
> >             print "Key is $key and value is " . $jar->get($key);
> >    $cookies{$key} = $jar->get($key);
> >         }
> >
> > And if I do just this
> >
> >         my $req = APR::Request::Apache2->handle( $r );
> >         my $jar = $req->jar;
> >   my $cookie = $jar->get('ISMH_SESSION_ID');
> >
> > I get the error of "Can't call method "get" on an undefined value"
> >
> > If it matters, I load the modules in my startup.pl
> > use Apache2::Request ();
> > use Apache2::RequestRec ();
> > use Apache2::Cookie ();
> > use Apache2::Const -compile => qw(REDIRECT);
> > use Apache2::Const -compile => qw(OK);
> > use APR::Table ();
> > use APR::Request ();
> > use APR::Request::Cookie ();
> >
> > Am I doing anything that is clearly wrong?
>
> Not to me, but it is too long since I wrote my code to remember the
> issues I had. I remember it took me a while to get it write.
>
> Here is what I use at the top of my module:
> use APR::Request qw/encode decode/;
> use APR::Request::Apache2();
> use APR::Request::Param();
> use APR::Request::Cookie();
> use APR::Table();
>
> Are you sure that libapreq is correctly installed?  Did you run make
> test?  Is it loaded in your httpd.conf file?
>
> I'm clutching at straws....
>
> good luck
>
> clint
>
>
>
>
>

________________________________________________________________________

Clinton Gormley clinton@traveljury.com

www.TravelJury.com - For travellers, By travellers






RE: Apache2::Cookie/APR::Request::Cookie

Posted by Clinton Gormley <cl...@traveljury.com>.
> After the cookie has been set...
>  
> my $req = APR::Request::Apache2->handle( $r );
> my $jar = $req->jar;
> print $req->jar_status();
>  
> Just gives me the error of "Missing Input Data" and I'm sure apreq2 is
> loaded.

from what John said:

> jar() returns undef if the browser sent no Cookie header - hence
> "can't call get method on undefined".

it sounds like your cookie isn't being sent by your browser back to your
web server.  i remember having some problems with the parameters I was
passing to the cookie.  Try just setting name and value and see what
happens there.

Also, check what headers your browser is sending back.  (The LiveHeader
add-on in firefox will do this for you)
>  
> Man, I wish getting rid of CGI.pm was as easy as using it :) - Back to
> the drawing board!!
>  
> Thanks
> -Chris
> 
>  
> 
> ______________________________________________________________________
> From: Clinton Gormley [mailto:clint@traveljury.com]
> Sent: Sat 12/9/2006 10:00 AM
> To: cfaust-dougot
> Cc: modperl@perl.apache.org
> Subject: RE: Apache2::Cookie/APR::Request::Cookie
> 
> 
> On Sat, 2006-12-09 at 09:37 -0500, cfaust-dougot wrote:
> > Thanks for the reply Clinton, I was just using the same request obj
> > from the handler, guess that was wrong :)
> > 
> > I tried your read example and now I don't get anything at all (even
> > though I can see the cookie on the machine)
> 
> What do you mean by 'I can see the cookie on the machine'?
> 
> Can you see in the browser that it is being set?
> 
> 
> > 
> >         my $req = APR::Request::Apache2->handle( $r );
> >         my $jar = $req->jar;
> 
> Try : print $req->jar_status();
> and see : perldoc APR::Request
> 
> >         my %cookies;
> >         foreach my $key ( keys %$jar ) {
> >             print "Key is $key and value is " . $jar->get($key);
> >    $cookies{$key} = $jar->get($key);
> >         }
> > 
> > And if I do just this
> > 
> >         my $req = APR::Request::Apache2->handle( $r );
> >         my $jar = $req->jar;
> >   my $cookie = $jar->get('ISMH_SESSION_ID');
> > 
> > I get the error of "Can't call method "get" on an undefined value"
> > 
> > If it matters, I load the modules in my startup.pl
> > use Apache2::Request ();
> > use Apache2::RequestRec ();
> > use Apache2::Cookie ();
> > use Apache2::Const -compile => qw(REDIRECT);
> > use Apache2::Const -compile => qw(OK);
> > use APR::Table ();
> > use APR::Request ();
> > use APR::Request::Cookie ();
> >
> > Am I doing anything that is clearly wrong?
> 
> Not to me, but it is too long since I wrote my code to remember the
> issues I had. I remember it took me a while to get it write.
> 
> Here is what I use at the top of my module:
> use APR::Request qw/encode decode/;
> use APR::Request::Apache2();
> use APR::Request::Param();
> use APR::Request::Cookie();
> use APR::Table();
> 
> Are you sure that libapreq is correctly installed?  Did you run make
> test?  Is it loaded in your httpd.conf file?
> 
> I'm clutching at straws....
> 
> good luck
> 
> clint
> 
> 
> 
> 
> 

________________________________________________________________________

Clinton Gormley clinton@traveljury.com

www.TravelJury.com - For travellers, By travellers




Re: Apache2::Cookie/APR::Request::Cookie

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
cfaust-dougot wrote:
> I can both see the cookie being sent in the browser, and I can view the 
> cookie itself on the filesystem after its been created...
>  
> After the cookie has been set...
>  
> my $req = APR::Request::Apache2->handle( $r );
> my $jar = $req->jar;
> print $req->jar_status();
See this test file as an example of using APR:: to read the cookies.
glue/perl/t/response/TestAPI/cookie.pm




-- 
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/EC88A0BF 0DE5 C55C 6BF3 B235 2DAB  B89E 1324 9B4F EC88 A0BF

I never had a dream come true
'Til the day that I found you.
Even though I pretend that I've moved on
You'll always be my baby.
I never found the words to say
You're the one I think about each day
And I know no matter where life takes me to
A part of me will always be...
A part of me will always be with you.

RE: Apache2::Cookie/APR::Request::Cookie

Posted by cfaust-dougot <cf...@doyougot.com>.
I can both see the cookie being sent in the browser, and I can view the cookie itself on the filesystem after its been created...
 
After the cookie has been set...
 
my $req = APR::Request::Apache2->handle( $r );
my $jar = $req->jar;
print $req->jar_status();
 
Just gives me the error of "Missing Input Data" and I'm sure apreq2 is loaded.
 
Man, I wish getting rid of CGI.pm was as easy as using it :) - Back to the drawing board!!
 
Thanks
-Chris

 
________________________________

From: Clinton Gormley [mailto:clint@traveljury.com]
Sent: Sat 12/9/2006 10:00 AM
To: cfaust-dougot
Cc: modperl@perl.apache.org
Subject: RE: Apache2::Cookie/APR::Request::Cookie



On Sat, 2006-12-09 at 09:37 -0500, cfaust-dougot wrote:
> Thanks for the reply Clinton, I was just using the same request obj
> from the handler, guess that was wrong :)
> 
> I tried your read example and now I don't get anything at all (even
> though I can see the cookie on the machine)

What do you mean by 'I can see the cookie on the machine'?

Can you see in the browser that it is being set?


> 
>         my $req = APR::Request::Apache2->handle( $r );
>         my $jar = $req->jar;

Try : print $req->jar_status();
and see : perldoc APR::Request

>         my %cookies;
>         foreach my $key ( keys %$jar ) {
>             print "Key is $key and value is " . $jar->get($key);
>    $cookies{$key} = $jar->get($key);
>         }
> 
> And if I do just this
> 
>         my $req = APR::Request::Apache2->handle( $r );
>         my $jar = $req->jar;
>   my $cookie = $jar->get('ISMH_SESSION_ID');
> 
> I get the error of "Can't call method "get" on an undefined value"
> 
> If it matters, I load the modules in my startup.pl
> use Apache2::Request ();
> use Apache2::RequestRec ();
> use Apache2::Cookie ();
> use Apache2::Const -compile => qw(REDIRECT);
> use Apache2::Const -compile => qw(OK);
> use APR::Table ();
> use APR::Request ();
> use APR::Request::Cookie ();
>
> Am I doing anything that is clearly wrong?

Not to me, but it is too long since I wrote my code to remember the
issues I had. I remember it took me a while to get it write.

Here is what I use at the top of my module:
use APR::Request qw/encode decode/;
use APR::Request::Apache2();
use APR::Request::Param();
use APR::Request::Cookie();
use APR::Table();

Are you sure that libapreq is correctly installed?  Did you run make
test?  Is it loaded in your httpd.conf file?

I'm clutching at straws....

good luck

clint





RE: Apache2::Cookie/APR::Request::Cookie

Posted by Clinton Gormley <cl...@traveljury.com>.
On Sat, 2006-12-09 at 09:37 -0500, cfaust-dougot wrote:
> Thanks for the reply Clinton, I was just using the same request obj
> from the handler, guess that was wrong :)
>  
> I tried your read example and now I don't get anything at all (even
> though I can see the cookie on the machine)

What do you mean by 'I can see the cookie on the machine'?

Can you see in the browser that it is being set?


>  
>         my $req = APR::Request::Apache2->handle( $r );
>         my $jar = $req->jar;

Try : print $req->jar_status();
and see : perldoc APR::Request

>         my %cookies;
>         foreach my $key ( keys %$jar ) {
>             print "Key is $key and value is " . $jar->get($key);
>    $cookies{$key} = $jar->get($key);
>         }
>  
> And if I do just this
>  
>         my $req = APR::Request::Apache2->handle( $r );
>         my $jar = $req->jar;
>   my $cookie = $jar->get('ISMH_SESSION_ID');
>  
> I get the error of "Can't call method "get" on an undefined value"
>  
> If it matters, I load the modules in my startup.pl
> use Apache2::Request ();
> use Apache2::RequestRec ();
> use Apache2::Cookie ();
> use Apache2::Const -compile => qw(REDIRECT);
> use Apache2::Const -compile => qw(OK);
> use APR::Table ();
> use APR::Request ();
> use APR::Request::Cookie ();
> 
> Am I doing anything that is clearly wrong?

Not to me, but it is too long since I wrote my code to remember the
issues I had. I remember it took me a while to get it write.

Here is what I use at the top of my module:
use APR::Request qw/encode decode/;
use APR::Request::Apache2();
use APR::Request::Param();
use APR::Request::Cookie();
use APR::Table();

Are you sure that libapreq is correctly installed?  Did you run make
test?  Is it loaded in your httpd.conf file?

I'm clutching at straws....

good luck

clint



RE: Apache2::Cookie/APR::Request::Cookie

Posted by cfaust-dougot <cf...@doyougot.com>.
Thanks for the reply Clinton, I was just using the same request obj from the handler, guess that was wrong :)
 
I tried your read example and now I don't get anything at all (even though I can see the cookie on the machine)
 
        my $req = APR::Request::Apache2->handle( $r );
        my $jar = $req->jar;
        my %cookies;
        foreach my $key ( keys %$jar ) {
            print "Key is $key and value is " . $jar->get($key);
   $cookies{$key} = $jar->get($key);
        }
 
And if I do just this
 
        my $req = APR::Request::Apache2->handle( $r );
        my $jar = $req->jar;
  my $cookie = $jar->get('ISMH_SESSION_ID');
 
I get the error of "Can't call method "get" on an undefined value"
 
If it matters, I load the modules in my startup.pl
use Apache2::Request ();
use Apache2::RequestRec ();
use Apache2::Cookie ();
use Apache2::Const -compile => qw(REDIRECT);
use Apache2::Const -compile => qw(OK);
use APR::Table ();
use APR::Request ();
use APR::Request::Cookie ();

Am I doing anything that is clearly wrong?
 
Thanks
-Chris
 

________________________________

From: Clinton Gormley [mailto:clint@traveljury.com]
Sent: Sat 12/9/2006 8:53 AM
To: cfaust-dougot
Cc: modperl@perl.apache.org
Subject: Re: Apache2::Cookie/APR::Request::Cookie




> 
> The man page then says to use APR::Request::Cookie I should:
> my $jar = $r->jar;
> my $cookie = $jar->get("ISMH_SESSION_ID");

What is $r in this case? It should be an APR::Request::Apache2 or
(APR::Request::CGI I think) handle.

So, where $r is an Apache2::RequestRec object:

To set:
-------
        my $cookie = APR::Request::Cookie->new(
            $r->pool,
            expires => '+7d',
            value => 'value',
            name  => 'name'
        ) or die;

        $r->err_headers_out->add( 'Set-Cookie', $cookie->as_string );
       
To read:
--------
        my $req = APR::Request::Apache2->handle( $r );
        my $jar = $req->jar;
        my %cookies;
        foreach my $key ( keys %$jar ) {
            $cookies{$key} = $jar->get($key);
        }


clint




Re: Apache2::Cookie/APR::Request::Cookie

Posted by Clinton Gormley <cl...@traveljury.com>.
>  
> The man page then says to use APR::Request::Cookie I should:
> my $jar = $r->jar;
> my $cookie = $jar->get("ISMH_SESSION_ID");

What is $r in this case? It should be an APR::Request::Apache2 or
(APR::Request::CGI I think) handle.

So, where $r is an Apache2::RequestRec object:

To set:
-------
        my $cookie = APR::Request::Cookie->new( 
            $r->pool,
            expires => '+7d',
            value => 'value',
            name  => 'name'
        ) or die;

        $r->err_headers_out->add( 'Set-Cookie', $cookie->as_string );
        
To read:
--------
        my $req = APR::Request::Apache2->handle( $r );
        my $jar = $req->jar;
        my %cookies;
        foreach my $key ( keys %$jar ) {
            $cookies{$key} = $jar->get($key);
        }


clint