Why can't you just do this in your config file:

ns_section "ns/server/${servername}/adp"
ns_param   map             "*"   ;# Any extension can be mapped.

This should not interfere with deliverty of any registered mime types
and should be as fast if not faster than the C patch.



From: John Buckman <[EMAIL PROTECTED]>
Reply-To: AOLserver Discussion <AOLSERVER@LISTSERV.AOL.COM>
To: AOLSERVER@LISTSERV.AOL.COM
Subject: [AOLSERVER] code patch to enable default filename extension
Date: Sat, 15 Apr 2006 14:55:29 +0100

I wanted to have a a default filename extension feature in aolserver, where http://localhost/foo fetches foo.adp, so that URLs in a web site don't need to show the .adp on every url.

I read in the archives that openacs has this feature via a filter written in tcl, but I wanted the implementation to be fast, minimal and relatively transparent, so I wrote my own patch.

What my code does is change a page fetch internally from:

http://localhost/foo
to
http://localhost/foo.adp

This .adp appending only occurs on URLs that have don't have an existing filename extension on them. Note that this patch also works correctly with directories that have a period in them.

I'm pretty sure my code below is harmless and appears bug-free, but it's not generic enough as it currently stands to warrant putting into the core. I could make it work of an
ns_param default_ext ".adp"

if the patch seems interesting to others and there were interest to put it into the core. Given that it's a very small amount of C code, the overhead should be minimal with this feature enabled.

To put this patch in, you should insert the code below in nsd/ request.c right above "request->url = ns_strdup(ds2.string);" Once you're happy with the patch you can remove the Ns_Log line.
====
/* john buckman added 4/14/06 */
/* check if should add default filename extension of .adp */
/* only if no / on end of url which indicates a directory */
char * dotpos;
if (ds2.string[ds2.length - 1] != '/') {
/* if not . in the entire url, or if there is a dot before the final / (indicating a . in a directory name, which is ok, then add the default filename extension */
    dotpos = strrchr(ds2.string, '.');
    if ((dotpos == NULL) || (strchr(dotpos, '/') != NULL)) {
        Ns_DStringAppend(&ds2, ".adp");
Ns_Log(Notice, "added default extension to get '%s'", ds2.string);
    }
}
/* end john buckman added */

request->url = ns_strdup(ds2.string);
===


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of your email blank.


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> 
with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.

Reply via email to