John Buckman wrote: > > On Jul 9, 2014, at 3:00 PM, Jeff Rogers <dv...@diphi.com > <mailto:dv...@diphi.com>> wrote: > >> There's no builtin way I know of to define a default extension. I would >> do this with a preauth filter, something like this: > > The preauth filter is a nice way to do it, albeit with a bit of file > existence checking overhead for every request that I'd prefer avoid. > > The way my C code worked (see previous msg) was to look to see if the > request url has no extension, and no trailing / on it either, and then > to append .adp in that case. That has the advantage of being very low > overhead.
I certainly understand the desire to minimize overhead. The tcl filter I posted could easily enough be changed to only look at the string values and not worry about checking for file existence. There is still the overhead of the filter call and the tcl code, however (my tests show this overhead in the 10-12 microsecond range). You can eliminate most of this overhead by implementing a filter in C rather than tcl, and the naviserver C api makes this easy. That would provide most of the performance boost you're looking for while being lots more flexible and easier to manage than by changing the guts of SetUrl. In particular, since it's a filter you can easily limit the functionality to one subdirectory. I created a simple extension to show the idea; it's at https://bitbucket.org/jeffr/nsdefext/src To build, clone it to a subfolder of your naviserver build folder, "cd nsdefext", and "make install". To use it, just add it to your modules in your conf file: ns_section "ns/server/default/modules" ns_param nssock nssock.so ns_param nslog nslog.so ns_param nsdefext nsdefext.so I haven't tested the code extensively, but the main body is about 10 lines, so it should be pretty simple to understand and modify. Admittedly it's been a while since I've written an apache extension, but I recall it being much more complex than this :) -J > > As you noted, Apache has this with MultiViews, and I use that feature > extensively on Magnatune.com <http://Magnatune.com> so that URLs look > nice and clean, ie: http://magnatune.com/artists/linda_wood > > So yes, I'd vote for this to be a config level feature, since it's > already in Apache that way. > > Looking at request.c it looks to me like the action happens in the > "SetUrl" function. > > Specifically, there already is logic in here to deal with trailing > slashes, so a default filename extension feature would slot in well at > this point: > > /* > * Append a trailing slash to the normalized URL if the original URL > * ended in slash that wasn't also the leading slash. > */ > > while (*url == '/') { > ++url; > } > if (*url != '\0' && url[strlen(url) - 1] == '/') { > Ns_DStringAppend(&ds2, "/"); > } > > /* > john - check to see if a default_extension has been set in the config > file, and if so, append it now if appropriate. > */ > > request->url = ns_strdup(ds2.string); > Ns_DStringFree(&ds2); > ------------------------------------------------------------------------------ _______________________________________________ naviserver-devel mailing list naviserver-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/naviserver-devel