You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Nick Kew <ni...@webthing.com> on 2005/10/04 17:17:50 UTC
Flexible Handlers
The current implementation of handlers is a little bizarre, with each
handler both having to register itself and check its own name.
I'm not sure where that comes from, but I can't help thinking the
ap_provider API might be a more rational way to declare handlers.
We have one frequently-requested feature that IMO we should support:
cascaded/fallback handlers. The request for this typically says "if a
document isn't there, then use my handler as backup". ErrorDocument
offers a limited workaround, but
(a) This shouldn't have to be an error path
(b) This should be able to cascade
So, how about AddHandler & friends taking a *list* of handlers as argument
(let's call the new version AddHandlerByExt)? Then we can run each handler
in turn until one returns a value other than DECLINED. That would be coupled
with the default handler being assigned a name and being configurable to
appear anywhere in the list, so "fall back to my CGI if there's no file of
that name" becomes "AddHandlerByExt .html default cgi-script".
ErrorDocuments are invoked when we fall off the end of the list.
For a slightly bigger change, we can use ap_provider on top of that to
declare and reference handlers.
--
Nick Kew
Re: Flexible Handlers
Posted by Brian Akins <br...@turner.com>.
Brian Akins wrote:
> This is interesting. But what if we had a "handler chain" much like a
> filter chain? First one to return OK stops the chain. Chains could be
> built up as one shots (like SetHandler) or more elaborate like
> mod_filter does with filters. the default_handler in core could always
> be added to the end.
Some pseudo config directives
<Location /stuff>
SetHandler stuff-handler
#Handler chain is now stuff-handler, default
</Location>
HandlerChain name-of-chain stuff-handler other-handler yet-another
<Location /stuff2>
SetHandlerChain name-of-chain
# handler chain is now stuff-handler, other-handler,
# yet-another, default
</Location>
<Location /more-stuff>
SetHandlerChain name-of-chain
AddHandler something-handler
#handler chain is now stuff-handler, other-handler,
# yet-another, something-handler default
</Location>
--
Brian Akins
Lead Systems Engineer
CNN Internet Technologies
Re: Flexible Handlers
Posted by Brian Akins <br...@turner.com>.
Nick Kew wrote:
> Indeed. But that's first one NOT to return DECLINED.
That's what I meant to say.
> I'd prefer not. It can be added anywhere, but needn't be implied except
> as a default (no explicit handler at all in effect).
>
sure. agreed.
--
Brian Akins
Lead Systems Engineer
CNN Internet Technologies
Re: Flexible Handlers
Posted by Nick Kew <ni...@webthing.com>.
On Tuesday 04 October 2005 16:25, Brian Akins wrote:
> Nick Kew wrote:
> > The current implementation of handlers is a little bizarre, with each
> > handler both having to register itself and check its own name.
>
> Some people, myself included, have handlers that run even when they
> aren't "set," ithey never check r->handler and always returns DECLINED.
> Yes, I know this is bad and should be done in fixups probably, but I'm
> sure this may break some things.
Sounds contrary to the API. Flexible configuration would presumably enable
you to insert them legitimately?
> That being said. I have always found it strange that everything has to
> check r->handler.
Exactly.
> What about cases like this?
>
> <Location /stuff>
> SetHandler stuff-handler
> </Location>
That's easy: no change as far as stuff-handler is concerned. SetHandler
gets to take extra args, but only if we want it (i.e. not in cases like that).
> > For a slightly bigger change, we can use ap_provider on top of that to
> > declare and reference handlers.
>
> This is interesting. But what if we had a "handler chain" much like a
> filter chain? First one to return OK stops the chain.
Indeed. But that's first one NOT to return DECLINED.
> Chains could be
> built up as one shots (like SetHandler) or more elaborate like
> mod_filter does with filters.
Even SetHandler could take more than one argument. In fact, that
should serve to make SetHandler compatible with Directory Indexes -
which people sometimes want in a cgi-bin type of situation.
> the default_handler in core could always
> be added to the end.
I'd prefer not. It can be added anywhere, but needn't be implied except
as a default (no explicit handler at all in effect).
--
Nick Kew
Re: Flexible Handlers
Posted by Brian Akins <br...@turner.com>.
Nick Kew wrote:
> The current implementation of handlers is a little bizarre, with each
> handler both having to register itself and check its own name.
Some people, myself included, have handlers that run even when they
aren't "set," ithey never check r->handler and always returns DECLINED.
Yes, I know this is bad and should be done in fixups probably, but I'm
sure this may break some things.
That being said. I have always found it strange that everything has to
check r->handler.
> appear anywhere in the list, so "fall back to my CGI if there's no file of
> that name" becomes "AddHandlerByExt .html default cgi-script".
> ErrorDocuments are invoked when we fall off the end of the list.
What about cases like this?
<Location /stuff>
SetHandler stuff-handler
</Location>
where stuff may have all sorts of extensions.
> For a slightly bigger change, we can use ap_provider on top of that to
> declare and reference handlers.
This is interesting. But what if we had a "handler chain" much like a
filter chain? First one to return OK stops the chain. Chains could be
built up as one shots (like SetHandler) or more elaborate like
mod_filter does with filters. the default_handler in core could always
be added to the end.
--
Brian Akins
Lead Systems Engineer
CNN Internet Technologies