You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Matt Sergeant <ma...@sergeant.org> on 2000/04/22 18:54:43 UTC

PerlHandler stopped working???

I'm so confused... I can't get my PerlHandler to work. It works sort of
fine as a PerlFixupHandler - only if I return "OK" from that it then
appends the entire file again to the end :(

This is mod_perl 1.22, and it's a .htaccess file I'm trying to define it
in. Here's the file:

__BEGIN__
DirectoryIndex index.xml index.html

# I added this but it made no difference
Options +ExecCGI

# this is required to set the MIME type.
PerlTypeHandler +Apache::MimeXML

SetHandler perl-script

# offending line!!!
PerlFixupHandler Apache::XMLStylesheet

PerlSetVar StylesheetMap "notxslt => Apache::XPath::NotXSLT"
__END__

When I change the "offending line" to:

PerlHandler Apache::XMLStylesheet

I just get the default handler - i.e. it gives me the raw index.xml file,
rather than processing it. I have no idea what's going on here... Also, I
can't seem to push_handlers(PerlHandler => ...) either - that just runs
the default handler as well.

What's strange about this, is on the same server I have a couple of
modules working just fine as a PerlHandler, and even in a .htaccess file.

The only thing I can think of, is that Apache::MimeXML is somehow stopping
the PerlHandler phase from being executed. Can it do that (but still allow
the PerlFixupHandler phase to execute)???

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org http://xml.sergeant.org


Re: PerlHandler stopped working???

Posted by "Randal L. Schwartz" <me...@stonehenge.com>.
>>>>> "Matt" == Matt Sergeant <ma...@sergeant.org> writes:

Matt> I guess one important question is - why do we have to call SetHandler for
Matt> PerlHandlers and not for any of the other handler phases. For all the
Matt> other phases Apache/mod_perl automatically figures out if there's a
Matt> handler installed and either runs perl code, or lets apache do its
Matt> work. Why can't PerlHandler do the same? (as you can tell - I haven't dug
Matt> into the internals of this - but I am curious).

I've been pondering this for quite some time, and was considering
a "magic mime type" that I'd deal with in the fixup handler... if
the MIME type assigned by mod_mime or anything else in the mime phase
is "text/html;PerlHandler=Apache::Registry", then the generic
fixup handler would patch that to "text/html" and push a PerlHandler
of Apache::Registry.

That way you could do this:

    <files *.html>
    SetType text/html;PerlHandler=HTML::Mason
    </files>

    <files *.pl>
    SetType text/plain;PerlHandler=Apache::Registry
    </files>

    <files static/*.html>
    SetType text/html
    </files>

Syntax is probably off... but I think you can see where I'm going with
this.  Bring the MIME type to mean both the "real" mime type as well
as a PerlHandler if needed.  I'm sure it's a 15 line
FixupHandler... just haven't had time to tear down part of my site to
test. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Re: PerlHandler stopped working???

Posted by Matt Sergeant <ma...@sergeant.org>.
On Tue, 25 Apr 2000, Doug MacEachern wrote:

> there's nothing to investigate, Apache is working as it is designed.
> if you feel this is a design flaw, the the issue should be raise on
> new-httpd@apache.org list.
> as i mentioned above,  alternative to the FixupHandler workaround, if your
> TypeHandler wants to let mod_mime contribute, it can run a subrequest and
> copy the $subr->{handler,content_type} as you see fit.

Sorted!

Apache::MimeXML, if it finds XML, now does:

$r->push_handlers('PerlFixupHandler',
	sub {
		my $r = shift;
		$r->content_type($type);
		$r->content_encoding($type);
	});
return DECLINED;

Which works in all situations. Thanks for your help, Doug. Maybe this
should go into the guide or something? Stas - want a brief write-up?

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org http://xml.sergeant.org


Re: PerlHandler stopped working???

Posted by Doug MacEachern <do...@covalent.net>.
> I do now - just uploaded a new version. It's still not correct though - a
> proper fix would have to pull SetHandler out of mod_mime altogether, I

you'd still have the same problem, Apache stops calling type handlers
after the first one returns OK.  besides, you can apply the SetHandler
config in your TypeHandler by using a subrequest, no need to pull it out
of mod_mime.
 
> I guess one important question is - why do we have to call SetHandler for
> PerlHandlers and not for any of the other handler phases. For all the
> other phases Apache/mod_perl automatically figures out if there's a
> handler installed and either runs perl code, or lets apache do its
> work. Why can't PerlHandler do the same? (as you can tell - I haven't dug
> into the internals of this - but I am curious).

because Apache dispatches response handlers based on the modules'
handler_rec (part of the module structure).  the key Apache uses to do
that lookup is r->handler, which if NULL, falls back to r->content_type.

> Right. So what's the point of PerlTypeHandler again?... ;-) Seriously
> though - Apache::MimeXML is the only PerlTypeHandler, as far as a quick
> search reveals, apart from your examples in the book. So maybe it would be
> worth investigating this further.

there's nothing to investigate, Apache is working as it is designed.
if you feel this is a design flaw, the the issue should be raise on
new-httpd@apache.org list.
as i mentioned above,  alternative to the FixupHandler workaround, if your
TypeHandler wants to let mod_mime contribute, it can run a subrequest and
copy the $subr->{handler,content_type} as you see fit.

> A fixup handler is an interesting solution... but can I stack
> FixupHandlers? (I run most of my mod_perl code from a FixupHandler).

yes.
 
> Also, you didn't pick up on something I sent to the list in another
> thread... I have code that goes:
> 
> if ($r->current_callback eq 'PerlFixupHandler') {
> 	$r->push_handlers('PerlHandler', \&code);
> }
> else {
> 	&code($r);
> }
> 
> so that I can install the module as either a fixup or a PerlHandler. The
> fixup installed version is 4 times slower than calling the function
> directly - is that to be expected? (we're talking 20 requests/sec vs 80
> here - a huge difference).

i wouldn't expect that much of a difference.  i'll look into it.


Re: PerlHandler stopped working???

Posted by Doug MacEachern <do...@covalent.net>.
On Fri, 5 May 2000, Matt Sergeant wrote:
 
> Really really freaky. However I assume you saw the post - I solved it by
> doing push_handler() with a Fixup and returning DECLINED. That way
> mod_mime gets to do its stuff, and my content_type still gets set
> regardless.

yeah, i know, it's cinco de mayo, so take that code with a tequilla shot
and some grains of salt ;)


Re: PerlHandler stopped working???

Posted by Matt Sergeant <ma...@sergeant.org>.
On Fri, 5 May 2000, Doug MacEachern wrote:

> On Tue, 25 Apr 2000, Matt Sergeant wrote:
>  
> > I do now - just uploaded a new version. It's still not correct though - a
> > proper fix would have to pull SetHandler out of mod_mime altogether, I
> > guess. For example, say your config contains:
> 
> oh yeah, i forgot, you can call mod_mime's fixup directly too:
> 
> use Apache::Module ();
> 
> my $rc = Apache::Module->top_module->find("mod_mime")->type_checker->($r);
> 
> that digs the type_checker function pointer out of the mod_mime module
> structure and returns a reference to an anonymous xsub, which calls that
> function.  neato, eh?

Really really freaky. However I assume you saw the post - I solved it by
doing push_handler() with a Fixup and returning DECLINED. That way
mod_mime gets to do its stuff, and my content_type still gets set
regardless.

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org http://xml.sergeant.org


Re: PerlHandler stopped working???

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 25 Apr 2000, Matt Sergeant wrote:
 
> I do now - just uploaded a new version. It's still not correct though - a
> proper fix would have to pull SetHandler out of mod_mime altogether, I
> guess. For example, say your config contains:

oh yeah, i forgot, you can call mod_mime's fixup directly too:

use Apache::Module ();

my $rc = Apache::Module->top_module->find("mod_mime")->type_checker->($r);

that digs the type_checker function pointer out of the mod_mime module
structure and returns a reference to an anonymous xsub, which calls that
function.  neato, eh?


Re: PerlHandler stopped working???

Posted by Matt Sergeant <ma...@sergeant.org>.
On Tue, 25 Apr 2000, Doug MacEachern wrote:

> > I guess the problem is that mod_mime implements SetHandler - and I'm not
> > convinced it should. If you were given the opportunity to do it all again
> 
> understood, but this is how apache is designed, mod_perl is just going
> with the flow here.
> 
> > I'd suggest it be done as follows:
> > 
> > If a PerlTypeHandler returns OK,  check if
> > @{$r->get_handlers('PerlHandler')} is true (i.e. there's a PerlHandler
> > waiting in the wings). If so, call $r->handler('perl-script').
> 
> so why not just do that in your PerlTypeHandler?

I do now - just uploaded a new version. It's still not correct though - a
proper fix would have to pull SetHandler out of mod_mime altogether, I
guess. For example, say your config contains:

# PerlTypeHandler blah
SetHandler perl-script
PerlFixupHandler foo

And in foo::handler() you call $r->push_handler('perl-script'). Suddenly
it stops working when you uncomment the PerlTypeHandler there.

I guess one important question is - why do we have to call SetHandler for
PerlHandlers and not for any of the other handler phases. For all the
other phases Apache/mod_perl automatically figures out if there's a
handler installed and either runs perl code, or lets apache do its
work. Why can't PerlHandler do the same? (as you can tell - I haven't dug
into the internals of this - but I am curious).

>  i don't think it's right
> for mod_perl to have that logic hardwired in.  the other solution, is to
> let mod_mime do it's thang in the type phase, and do your thang in the
> fixup phase to override anything mod_mime did that you don't want.

Right. So what's the point of PerlTypeHandler again?... ;-) Seriously
though - Apache::MimeXML is the only PerlTypeHandler, as far as a quick
search reveals, apart from your examples in the book. So maybe it would be
worth investigating this further.

A fixup handler is an interesting solution... but can I stack
FixupHandlers? (I run most of my mod_perl code from a FixupHandler).

Also, you didn't pick up on something I sent to the list in another
thread... I have code that goes:

if ($r->current_callback eq 'PerlFixupHandler') {
	$r->push_handlers('PerlHandler', \&code);
}
else {
	&code($r);
}

so that I can install the module as either a fixup or a PerlHandler. The
fixup installed version is 4 times slower than calling the function
directly - is that to be expected? (we're talking 20 requests/sec vs 80
here - a huge difference).

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org http://xml.sergeant.org


Re: PerlHandler stopped working???

Posted by Doug MacEachern <do...@covalent.net>.
> I guess the problem is that mod_mime implements SetHandler - and I'm not
> convinced it should. If you were given the opportunity to do it all again

understood, but this is how apache is designed, mod_perl is just going
with the flow here.

> I'd suggest it be done as follows:
> 
> If a PerlTypeHandler returns OK,  check if
> @{$r->get_handlers('PerlHandler')} is true (i.e. there's a PerlHandler
> waiting in the wings). If so, call $r->handler('perl-script').

so why not just do that in your PerlTypeHandler?  i don't think it's right
for mod_perl to have that logic hardwired in.  the other solution, is to
let mod_mime do it's thang in the type phase, and do your thang in the
fixup phase to override anything mod_mime did that you don't want.


Re: PerlHandler stopped working???

Posted by Matt Sergeant <ma...@sergeant.org>.
On Tue, 25 Apr 2000, Doug MacEachern wrote:

> On Sat, 22 Apr 2000, Matt Sergeant wrote:
> 
> > On Sat, 22 Apr 2000, Matt Sergeant wrote:
> > 
> > > The only thing I can think of, is that Apache::MimeXML is somehow stopping
> > > the PerlHandler phase from being executed. Can it do that (but still allow
> > > the PerlFixupHandler phase to execute)???
> > 
> > OK, it was Apache::MimeXML... Which is very odd indeed. A bug in mod_perl
> > by the looks of things. All I'm returning from Apache::MimeXML, btw, is
> > OK or DECLINED. It was returning OK when PerlHandler stopped working. For
> > now I'll disable it, and set Mime types manually for .xml files - but
> > something is seriously not right there.
> 
> as i already explained to matt in another email, if a TypeHandler returns
> OK, then mod_mime's type handler is not called.  which means that
> SetHandler, AddType, etc., for that require will be ignored, unless you
> return DECLINED or implement them yourself (see Apache::MIME in ch8 of
> the eagle book)

OK, I'm looking at that now, and I realise you're just passing it straight
through to apache to do the right thing, but I think it's the wrong
thing... Hear me out.

Apache::MimeXML, like most non-PerlHandler handlers, is not designed as a
replacement for mod_mime, but to build on it. If I detect something as
XML, I'd like to say "OK, I'm done with this phase, let the next
continue". Likewise if I don't want to handle this phase (i.e. I want
mod_mime to do its thang) I return DECLINED. I don't want a MIME handler
that's supposed to add to mod_mime to change the fact that I have a
PerlHandler setup. In order to build Apache::MimeXML properly, I'd have to
build an entire replacement for mod_mime, in XS, parsing the configuration
for SetHandler, and I don't want to do that.

I guess the problem is that mod_mime implements SetHandler - and I'm not
convinced it should. If you were given the opportunity to do it all again
I'd suggest it be done as follows:

If a PerlTypeHandler returns OK,  check if
@{$r->get_handlers('PerlHandler')} is true (i.e. there's a PerlHandler
waiting in the wings). If so, call $r->handler('perl-script').

If a PerlTypeHandler returns DECLINED, do it as you do now.

That should be backwards compatible with most code, I think. And not
interfere with things already setup in peoples httpd.conf/htaccess
files. Alternatively have the OK case remain the same, and have a new
return value (DONE?) that signfies to do the SetHandler part of mod_mime.

Convince me I'm thinking wrong, then I can get back to some real work ;-)

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org http://xml.sergeant.org


Re: PerlHandler stopped working???

Posted by Doug MacEachern <do...@covalent.net>.
On Sat, 22 Apr 2000, Matt Sergeant wrote:

> On Sat, 22 Apr 2000, Matt Sergeant wrote:
> 
> > The only thing I can think of, is that Apache::MimeXML is somehow stopping
> > the PerlHandler phase from being executed. Can it do that (but still allow
> > the PerlFixupHandler phase to execute)???
> 
> OK, it was Apache::MimeXML... Which is very odd indeed. A bug in mod_perl
> by the looks of things. All I'm returning from Apache::MimeXML, btw, is
> OK or DECLINED. It was returning OK when PerlHandler stopped working. For
> now I'll disable it, and set Mime types manually for .xml files - but
> something is seriously not right there.

as i already explained to matt in another email, if a TypeHandler returns
OK, then mod_mime's type handler is not called.  which means that
SetHandler, AddType, etc., for that require will be ignored, unless you
return DECLINED or implement them yourself (see Apache::MIME in ch8 of
the eagle book)


Re: PerlHandler stopped working???

Posted by Matt Sergeant <ma...@sergeant.org>.
On Sat, 22 Apr 2000, Matt Sergeant wrote:

> The only thing I can think of, is that Apache::MimeXML is somehow stopping
> the PerlHandler phase from being executed. Can it do that (but still allow
> the PerlFixupHandler phase to execute)???

OK, it was Apache::MimeXML... Which is very odd indeed. A bug in mod_perl
by the looks of things. All I'm returning from Apache::MimeXML, btw, is
OK or DECLINED. It was returning OK when PerlHandler stopped working. For
now I'll disable it, and set Mime types manually for .xml files - but
something is seriously not right there.

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org http://xml.sergeant.org