You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Broc Seib <bs...@icd.ics.purdue.edu> on 2002/09/22 18:23:22 UTC

managing cookies: mod_perl vs. Apache::ASP

Hi all,

I have a mix of Apache::ASP code and mod_perl code. Specifically, I use
Apache::ASP to do the bulk of my site's dynamic pages, plus I have written
some mod_perl handlers where I've needed to alter server behavior. One of
these mod_perl handlers does authorization, which is germane to this note
on managing cookies.

I needed to access the cookies created by Apache::ASP code from inside
my mod_perl handler. I typically use the CGI::Cookie module in mod_perl
to manage cookies. Alas, the way CGI::Cookie does its parse of the cookie
is not compatible with how Apache::ASP stored the cookie payload; the
parsing gets hung up on the '=' character in the payload.

So for now I copied into my mod_perl module the following subroutines
from Apache::ASP (from package Apache::ASP::Request):  Unescape(),
ParseParams(), and a snippet from new() that gets cookies. I had to
tweek these just a little bit to interface with my code. This works.

However, I don't think this is a good long term solution. I ought to
be able to access cookies the "Apache::ASP way" from mod_perl. It woiuld
be better whenever I do version upgrades of Apache::ASP. I would really
just like to be able to say in my mod_perl module:

  package MyApacheAccessHandler;

  use Apache::ASP;

  ## code code code
  ## code code code

  sub _check_for_ticket {
    my $r = shift;
    my $cookie_name = shift;

    ## get cookies via Apache::ASP API
    my $c = Apache::ASP::Request::ReadCookies($r);  ## or something...

	## (ignore my 70x code nomenclature....)
    return (701, 'no cookies or cookie headers') unless $c;
    return (703, 'user has no ticket' ) unless $c->{$cookie_name};

	## found it
    return (0, $c->{$cookie_name});
}


I can work on a patch that meshes well with mod_perl if there's anyone
else out these in this boat too...

Comments?

Broc

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: managing cookies: mod_perl vs. Apache::ASP

Posted by Josh Chamas <jo...@chamas.com>.
Broc Seib wrote:
> Hi all,
> 
> I have a mix of Apache::ASP code and mod_perl code. Specifically, I use
> Apache::ASP to do the bulk of my site's dynamic pages, plus I have written
> some mod_perl handlers where I've needed to alter server behavior. One of
> these mod_perl handlers does authorization, which is germane to this note
> on managing cookies.
> 
> I needed to access the cookies created by Apache::ASP code from inside
> my mod_perl handler. I typically use the CGI::Cookie module in mod_perl
> to manage cookies. Alas, the way CGI::Cookie does its parse of the cookie
> is not compatible with how Apache::ASP stored the cookie payload; the
> parsing gets hung up on the '=' character in the payload.
> 

I apologize for this difference, but the way IIS/ASP serialized cookies
was different than the way CGI, & I ported the ASP method over at first cut.

It may seem like overkill, but you might try to access the cookies via
a $Request object at runtime like this:

   my $ASP = Apache::ASP->new($r);
   my $Cookies = $ASP->Request->Cookies;

Just make sure to set $r->dir_config('NoState', 1) before doing this
so you do not init $Session & $Application objects during this invocation.

This method of out of Apache::ASP handler invocation is guaranteed to
work in future releases because I test for it at t/asp_object.t
I should really document this method better in the online docs.

There is overhead to creating ASP objects, but this is probably on
the order of 500-1000 per second & also gives you access to the
rest of the objects created.

Regards,

Josh
________________________________________________________________
Josh Chamas, Founder                   phone:925-552-0128
Chamas Enterprises Inc.                http://www.chamas.com
NodeWorks Link Checking                http://www.nodeworks.com


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org