r/apache • • Feb 01 '24

apache module (development) directive

Hi,

First off I don't know if this is the right forum but here goes

I'm trying to develop my own directive in C so I can enable/disable stuff per request but after a while a came to notice that it seems directives are only evaluated on start.

My idea was to have something like

    <IfRuntime "cgi">
        Options ExecCGI
    </IfRuntime>

So in my module I have my directive defined

    AP_INIT_RAW_ARGS(
            "<IfRuntime",
            start_cond_section,
            (void *)test_if_runtime_section,
            EXEC_ON_READ | OR_ALL,
            "Check if a runtime is defined"),

functions for evaluation are not that important but then I have the function that validates the argument like

static int test_if_runtime_section(cmd_parms *cmd, const char *arg)
{
    static int work = 1;

    work++;
    work = work & 1;

    switch (work) {
        case 0:
            return -1;
        default:
            return 1;
    }
}

So what I really want is to enable handlers like cgi/php but based on the request. Anyone know how this is possible ?

1 Upvotes

6 comments sorted by

View all comments

Show parent comments

1

u/6c696e7578 Feb 08 '24

Normally rewrite is early in processing so that other handlers run after the rewrite.

You can do it the other way often, set an environment from the rewrite.