httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Behlendorf <>
Subject Apache module question (fwd)
Date Mon, 11 Sep 1995 21:03:08 GMT

---------- Forwarded message ----------
Date: Mon, 11 Sep 95 10:18:00 PDT
From: Bill Radcliffe <>
To: owner-new-httpd <>
Subject: Apache module question

Could someone help me with a module development question?

I have written an Apache module that intercepts URLS that match a pattern 
(like /COMMAND/ARG/xxx/yyy/zzz.html) and converts them to other URLS. The 
translated URL is NOT (I repeat NOT) an actual filename on my server. It 
needs to be processed through Aliases, etc, as usual! If this were not the 
case, I would simple use Aliases.

I would like to handle this operation entirely during the translate phase, 
but found that I needed to write a handler to redirect the translated URL.

My first two attempts went like this ...

1) Convert and replace the original r->uri with my new r->uri and return OK 
(translate phase only)
2) Convert and replace the original r->uri with my new r->uri and return 
DECLINED (translate phase only)

SAMPLE CODE for 1) and 2).

int translate_commands (request_rec *r)
    void *server_conf = server->module_config;
    char *other_path = (char *)get_module_config(server_conf, 
    table *e = r->subprocess_env;
    char *name = r->uri;
    char *w1, *w2, *s;

    s = name;
    /* skip leading delimiter if there */
    if (*s == '/') s++;

    /* get the first word out of the path (the command) and match it */
    w1 = getword(r->pool, &s, '/');
    if (!w1 || !s)
        return DECLINED;
    if (strcasecmp (w1, "COMMAND"))
        return DECLINED;

    /* get the second word out of the path (the operand) and save it */
    w2 = getword(r->pool, &s, '/');
    if (!w2 || !s)
        return DECLINED;
    table_set (e, "COMMAND", w2);

    if (name[0] == '/')
        r->uri = pstrcat (r->pool, *other_path , "/", s, NULL);
        r->uri = pstrdup (r->pool, s);

    parse_uri(r, r->uri);  /* tried this - does not seem to help */
     /* return OK; */
    return DECLINED;

All the other modules seemed to think that the URL was now a real filename 
and did not need to be processed anymore - even after changing from OK to 

3) Convert the original r->uri to a r->filename and return OK in combination 

with a handler that internally redirects the request in the handler. 
(translate phase and handler combination). YUUUCK!  I will not send this 
code along since I do not want my name attached to it. Unfortunately, it 
works!  The problem is that it causes other modules to break and has other 
bad consequences.


William Radcliffe, Principal Engineer, Corbis

View raw message