|
From: Decent E. <dec...@gm...> - 2025-08-14 14:58:32
|
For many years, I’ve patched nsd/request.c so that http requests that do not have an extension specified, auto-add .adp. If an extension is specified (ie, jpg) the add nothing. And the .adp appended to the url is never shown to the site visitor. This gives me very clean URLs like: http://mydomain.com/user/edit which actually resolve to: http://mydomain.com/user/edit.adp Those are nicely human readable. Most every server-side parsing http servers show the filename extension, and I find it a nice advantage of using nsd that I don’t have to. I’m wondering what cleaner way there is to do this, in a high performance way? I could use ns_register_proc for every page, but then I don’t get the use of ADP pages: ns_register_proc GET /battery/* direct_battery 0 I could register a 404 handler, redirect to the .adp page, and then use javascript to rewrite the URL to remove .adp, but that’s pretty ugly engineering. -john Here’s my original C code for nsd/request.c: ==== /* 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); === |