You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Josh Chamas <jo...@chamas.com> on 2003/05/05 21:43:47 UTC
Re: ASP-Object in PerlAuth Handler
Dr. Helmut Zeilinger wrote:
> Hi,
>
> I get the Apache::ASP object in a ModPerl PerlAuthenHandler via
> (as described in the manual):
>
> <Perl>
> use Apache::ASP;
> sub My::Auth::handler {
> my $r = shift;
> my $ASP = Apache::ASP->new($r)
> my $Session = $ASP->Session;
> }
> </Perl>
>
If you want to prevent the ASP $Request object from reading form POST data,
then you could precede the object construction with:
sub My::Auth::handler {
local $ENV{CONTENT_LENGTH} = 0;
my $ASP = Apache::ASP->new($r);
ASP $Request uses that value to determine whether it reads data from POST.
We might also create a config for this that could be set like:
$r->dir_config('AllowRequest', 'Off');
so that you can prevent the Request object from being created in the first
request.
Certainly it seems that this can be improved on.... perhaps ASP objects created
across different mod_perl stages would end reusing previously created
Request objects ? I'll need to look at this for a better long term fix,
and am open to ideas.
Thanks,
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
Re: ASP-Object in PerlAuth Handler
Posted by "Dr. Helmut Zeilinger" <h....@envirotex.de>.
Hi,
--On Mittwoch, 7. Mai 2003 11:35 -0700 Josh Chamas <jo...@chamas.com> wrote:
> Dr. Helmut Zeilinger wrote:
> >
>> One might argue, that if there is no CONTENT_LENGTH, the request POST
>> data are also not fetched, and so my original problem does not exist.
>> But it seems
>> to be so, that only sometimes the POST data are fetched in the previous
>> handler (???)
>>
>
> That is odd. I tend not to trust %ENV setup in other stages myself, and
> to this effect, I will try to move away from using %ENV in the core
> Apache::ASP for consistent behavior in earlier stages, and instead rely
> on other things that are explicit like client HTTP headers.
>
Probably a good idea to get all the information from the Apache-Request
object itself.
(like for ex. $r->headers_in ("content-length") etc.)
>> For now i am using your workaround
>>
>> sub My::Auth::handler {
>> local $ENV{CONTENT_LENGTH} = 0;
>> my $ASP = Apache::ASP->new($r);
>>
>
> How about we create an explicit configration setting for this like:
>
> sub My::Auth::handler {
> $r->dir_config('RequestBinaryRead', 'Off);
> my $ASP = Apache::ASP->new($r);
> $r->dir_config('RequestBinaryRead', 'On');
> ...
>
> My only concern is that the %ENV hack may go away one day as it relies
> on internal implementation. But if we wrap an explicit config around
> it, I can make this work going forward. I thought about the caching
> of Request or ASP objects, but that seems too messy to get right for now,
> so I'd rather deal with the specific problem of handling POST data.
>
> I might also be able to set the default for this value to be On only
> for the PerlHandler / PerlResponseHandler, whereas other mod_perl callback
> stages will have this turned off by default, so for you then it would
> just work without explicitly setting the config. I think this would make
> the most intuitive sense, to have POST data only read during a PerlHandler
> phase unless explicitly configured otherwise.
>
I agree, that the solution with the 'RequestBinaryRead' config parameter
would be
much better than the %ENV way, because one does not have to rely on the
"internal" ASP
code, rather than on an "official" config parameter.
Setting the 'RequestBinaryRead' to 'Off' as default value in an other
mod_perl handler than the
response handler would be ok, but there might be users, who need the post
data in that handler
(for what reason ever) and are expecting it to work as "usual". Anyway, i
would always prefere
to set this parameter expilcitly, because then i am independend of any
change of the default
value.
Of course i agree, that caching of the ASP object would be the most elegant
and effective way, because
work that has once been done in a previous handler need not be done again.
But i can imagine, that is
much work to get rid of the %ENV dependency (and possibly other things to
make this work safely).
But in principal the $r->pnotes way to store the ASP object should work. Of
course there may be other
ways to store and retreive this object during one request.
In any case, as you pointed out, before reusing the ASP object, it should
be checked against changes
(e.g. filename etc.), and in case, being readjusted or destroyed and newly
created.
Thanks
Helmut
---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org
Re: ASP-Object in PerlAuth Handler
Posted by Josh Chamas <jo...@chamas.com>.
Dr. Helmut Zeilinger wrote:
>
> One might argue, that if there is no CONTENT_LENGTH, the request POST data
> are also not fetched, and so my original problem does not exist. But it
> seems
> to be so, that only sometimes the POST data are fetched in the previous
> handler (???)
>
That is odd. I tend not to trust %ENV setup in other stages myself, and
to this effect, I will try to move away from using %ENV in the core Apache::ASP
for consistent behavior in earlier stages, and instead rely on other things
that are explicit like client HTTP headers.
> For now i am using your workaround
>
> sub My::Auth::handler {
> local $ENV{CONTENT_LENGTH} = 0;
> my $ASP = Apache::ASP->new($r);
>
How about we create an explicit configration setting for this like:
sub My::Auth::handler {
$r->dir_config('RequestBinaryRead', 'Off);
my $ASP = Apache::ASP->new($r);
$r->dir_config('RequestBinaryRead', 'On');
...
My only concern is that the %ENV hack may go away one day as it relies
on internal implementation. But if we wrap an explicit config around
it, I can make this work going forward. I thought about the caching
of Request or ASP objects, but that seems too messy to get right for now,
so I'd rather deal with the specific problem of handling POST data.
I might also be able to set the default for this value to be On only
for the PerlHandler / PerlResponseHandler, whereas other mod_perl callback
stages will have this turned off by default, so for you then it would
just work without explicitly setting the config. I think this would make
the most intuitive sense, to have POST data only read during a PerlHandler
phase unless explicitly configured otherwise.
What do you think?
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
Re: ASP-Object in PerlAuth Handler
Posted by "Dr. Helmut Zeilinger" <h....@envirotex.de>.
Hallo,
further testing let me come to the result, that setting up the
asp object in an earlier apache phase does not work correctly. The
reason is, that the %ENV hash seems to be filled through the single
phases. For example in the PerlAuthen phase the only keys of %ENV are
PATH, GATEWAY_INTERFACE and MOD_PERL.
Because you make use of this hash during the object creation, it probably
might not work correctly.
One might argue, that if there is no CONTENT_LENGTH, the request POST data
are also not fetched, and so my original problem does not exist. But it
seems
to be so, that only sometimes the POST data are fetched in the previous
handler (???)
Anyway, what i was originally intending was the creation of the Session
object
in the Authen phase to check if the user has as valid session key. It would
of course be
nice to get the Session object "alone" without the price of setting up the
whole
ASP object.
For now i am using your workaround
sub My::Auth::handler {
local $ENV{CONTENT_LENGTH} = 0;
my $ASP = Apache::ASP->new($r);
to ensure, that the POST data are not fetched (=lost).
I keep thinking about this.
Thank You!
Helmut
> I have thought of automating this before. Would something like
> a configuration directive be appropriate like:
>
> PerlSetVar ASPRequestSingleton 1
>
> When set it would allow for caching & reusing of a single ASP object
> across request stages. This allows things like $Request, $Session, etc.
> to only be created once. Might the 1 instead be instead by Name, like
>
> PerlSetVar ASPRequestSingleton SomeName
>
> so one could have multiple tracks of ASP objects concurrently?
> A typical setting of 1 would simply be that cache name.
>
> This would effective restore a cached ASP object like your code
> has done across stages.
>
> Any suggestions on this feature? Does this need to be more flexible,
> or are there things not considered here? I would worry about someone
> creating such an object in an early stage, then changing the filename
> of the current request during a URI translation phase, and then having
> to deal with an old ASP object that was pointing to the wrong file.
> In fact, in an early enough Apache request stage, there may not even
> be a valid file that the ASP object would reference, so what then?
>
---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org
Re: ASP-Object in PerlAuth Handler
Posted by Josh Chamas <jo...@chamas.com>.
Dr. Helmut Zeilinger wrote:
>
> I took your idea of reusing or keeping the ASP object, which was created
> by a
> previous perl handler, during the whole request.
>
> Something like the following SEEMS to work (only a few tests!):
>
> Code in a previous handler (eg. PerlAuthenHandler):
>
> [..]
> #Create the ASP object
> my $ASP = Apache::ASP::new('Apache::ASP', $r, $r->filename);
>
> #Put it in $r->pnotes for reuse in the ResponseHandler
> $r->pnotes ('Apache::ASP'=> $ASP);
> [..]
I have thought of automating this before. Would something like
a configuration directive be appropriate like:
PerlSetVar ASPRequestSingleton 1
When set it would allow for caching & reusing of a single ASP object
across request stages. This allows things like $Request, $Session, etc.
to only be created once. Might the 1 instead be instead by Name, like
PerlSetVar ASPRequestSingleton SomeName
so one could have multiple tracks of ASP objects concurrently?
A typical setting of 1 would simply be that cache name.
This would effective restore a cached ASP object like your code
has done across stages.
Any suggestions on this feature? Does this need to be more flexible,
or are there things not considered here? I would worry about someone
creating such an object in an early stage, then changing the filename
of the current request during a URI translation phase, and then having
to deal with an old ASP object that was pointing to the wrong file.
In fact, in an early enough Apache request stage, there may not even
be a valid file that the ASP object would reference, so what then?
--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
Re: ASP-Object in PerlAuth Handler
Posted by "Dr. Helmut Zeilinger" <h....@envirotex.de>.
--On Montag, 5. Mai 2003 12:43 -0700 Josh Chamas <jo...@chamas.com> wrote:
> Dr. Helmut Zeilinger wrote:
>> Hi,
>>
>> I get the Apache::ASP object in a ModPerl PerlAuthenHandler via
>> (as described in the manual):
>>
>> <Perl>
>> use Apache::ASP;
>> sub My::Auth::handler {
>> my $r = shift;
>> my $ASP = Apache::ASP->new($r)
>> my $Session = $ASP->Session;
>> }
>> </Perl>
>>
>
> If you want to prevent the ASP $Request object from reading form POST
> data, then you could precede the object construction with:
>
> sub My::Auth::handler {
> local $ENV{CONTENT_LENGTH} = 0;
> my $ASP = Apache::ASP->new($r);
>
> ASP $Request uses that value to determine whether it reads data from POST.
>
> We might also create a config for this that could be set like:
>
> $r->dir_config('AllowRequest', 'Off');
>
> so that you can prevent the Request object from being created in the first
> request.
>
> Certainly it seems that this can be improved on.... perhaps ASP objects
> created across different mod_perl stages would end reusing previously
> created Request objects ? I'll need to look at this for a better long
> term fix, and am open to ideas.
>
I took your idea of reusing or keeping the ASP object, which was created by
a
previous perl handler, during the whole request.
Something like the following SEEMS to work (only a few tests!):
Code in a previous handler (eg. PerlAuthenHandler):
[..]
#Create the ASP object
my $ASP = Apache::ASP::new('Apache::ASP', $r, $r->filename);
#Put it in $r->pnotes for reuse in the ResponseHandler
$r->pnotes ('Apache::ASP'=> $ASP);
[..]
Code changed in the Apache::ASP::handler:
[..]
my $self;
if (ref ($r->pnotes ('Apache::ASP')) eq 'Apache::ASP')
{
$r->log_error("ASP object already created!");
$self = $r->pnotes ('Apache::ASP');
#Set filename (again ?)
$self->{'filename'} = $filename;
}
else
{
# ASP object creation, a lot goes on in there!
# method call used for speed optimization, as OO calls are slow
$self = Apache::ASP::new('Apache::ASP', $r, $filename);
}
[..]
Thanks
Helmut
---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org