You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Mark Harrison <mh...@pixar.com> on 2007/08/13 00:13:02 UTC

why is my module being called for all pages?

warning: newbie alert!

I've got a simple module as detailed below.  I based it off
of the example module, stripping it down to the smallest
example I could.

It seems to be working, but it is getting called on all
web pages.  Can someone loan me a clue as to:

1.  why it is being called on all pages, not just the
     one I've specified in <Location>?

2.  what do I need to do to fix it?

Many TIA!
Mark

### httpd.conf
### I expect the that http://localhost/kaptest to trigger
### but not http://localhost/somewhere_else
###
LoadModule kap_module         modules/mod_kap.so
<Location /kaptest>
SetHandler kap-handler
</Location>




/* mod_kap.c -- simple handler */
/*headers as per mod_example */

module AP_MODULE_DECLARE_DATA kap_module;

static int kap_handler(request_rec *r)
{
     ap_set_content_type(r, "text/plain");
     ap_rprintf(r, "kap_handler: time=%d\n", time(NULL));
     return OK;
}

static void kap_register_hooks(apr_pool_t *p)
{
     ap_hook_handler(kap_handler, NULL, NULL, APR_HOOK_MIDDLE);
}

module AP_MODULE_DECLARE_DATA kap_module =
{
     STANDARD20_MODULE_STUFF,
     NULL,                     /* per-directory config creator */
     NULL,                     /* dir config merger */
     NULL,                     /* server config creator */
     NULL,                     /* server config merger */
     NULL,                 /* command table */
     kap_register_hooks,       /* set up other request processing hooks */
};
/* eof: mod_kap.c */

-- 
Mark Harrison
Pixar Animation Studios

Re: why is my module being called for all pages?

Posted by Mark Harrison <mh...@pixar.com>.
Sander Temme wrote:
> 
> On Aug 12, 2007, at 3:13 PM, Mark Harrison wrote:
> 
>> warning: newbie alert!
> 
> We all were newbies once.
> 
>> I've got a simple module as detailed below.  I based it off
>> of the example module, stripping it down to the smallest
>> example I could.
>>
>> It seems to be working, but it is getting called on all
>> web pages.  Can someone loan me a clue as to:
>>
>> 1.  why it is being called on all pages, not just the
>>     one I've specified in <Location>?
> 
> All hooks are called for all requests.  For run-all hooks, the handlers 
> of all modules will be called.  For run-first hooks, hook handlers for 
> all modules are called until one returns something other than DECLINED.

Ah, that fixes it.  Thanks Sander and Frank!

Rgds,
Mark

Re: why is my module being called for all pages?

Posted by Sander Temme <sc...@apache.org>.
On Aug 12, 2007, at 3:13 PM, Mark Harrison wrote:

> warning: newbie alert!

We all were newbies once.

> I've got a simple module as detailed below.  I based it off
> of the example module, stripping it down to the smallest
> example I could.
>
> It seems to be working, but it is getting called on all
> web pages.  Can someone loan me a clue as to:
>
> 1.  why it is being called on all pages, not just the
>     one I've specified in <Location>?

All hooks are called for all requests.  For run-all hooks, the  
handlers of all modules will be called.  For run-first hooks, hook  
handlers for all modules are called until one returns something other  
than DECLINED.

> 2.  what do I need to do to fix it?

Pull in a little bit more from mod_example, where it makes a string  
comparison to the handler name.  If matched, do your thing.  If not  
matched, return DECLINED.

Your module will always be called, so keep the code path used to  
decline handling as short as possible.

S.

-- 
Sander Temme
sctemme@apache.org
PGP FP: 51B4 8727 466A 0BC3 69F4  B7B8 B2BE BC40 1529 24AF




Re: why is my module being called for all pages?

Posted by Frank Jones <jo...@gmail.com>.
On 8/12/07, Mark Harrison <mh...@pixar.com> wrote:
> I've got a simple module as detailed below.  I based it off
> of the example module, stripping it down to the smallest
> example I could.
>
> It seems to be working, but it is getting called on all
> web pages.  Can someone loan me a clue as to:
>
> 1.  why it is being called on all pages, not just the
>      one I've specified in <Location>?

that's to be expected.

> 2.  what do I need to do to fix it?

you have to compare the request_rec->handler field to the handler name
you specified in the config with the SetHandler directive. For
example, if you have:

<Location /mylocation>
    SetHandler myhandler
</Location>

in your config, then your module will need to do something like this
in whatever function you registered as the handler function:

    if (strcmp(r->handler, "myhandler")) {
        return DECLINED;
    }


Frank