|
Home > Archive > AOL Webserver > April 2006 > code patch to enable default filename extension
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
code patch to enable default filename extension
|
|
| John Buckman 2006-04-17, 11:56 pm |
| 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);
===
| |
| dhogaza@PACIFIER.COM 2006-04-17, 11:56 pm |
| > I'm pretty sure my code below is harmless and appears bug-free...
Well, it would break OpenACS. If such a feature is added, it should be
optional and configurable.
| |
| John Buckman 2006-04-17, 11:56 pm |
| On Apr 15, 2006, at 4:07 pm, dhogaza@PACIFIER.COM wrote:
>
> Well, it would break OpenACS. If such a feature is added, it
> should be
> optional and configurable.
What I was suggesting was a new optional parameter in config.tcl:
ns_param default_ext ".adp"
which would, in the sample-config.tcl file, be commented out and thus
have no effect. Only if you enable it would this patch take effect.
What I'd like to know is if others would find this feature useful.
-john
ps:
One small bug in what I sent to the list. In case anyone tried to
compile the change and you're using an older C compiler, you need to
move the
char * dotpos;
to the top of the function, like so:
static void
SetUrl(Ns_Request * request, char *url)
{
Ns_DString ds1, ds2;
char *p;
char * dotpos;
otherwise you'll get a compile time error.
-john
| |
| Tom Jackson 2006-04-17, 11:56 pm |
| I think you will find very little agreement on how something like this should
be configured, having only one option, instead of an ordered list makes it
less useful. Patching the core in this critical spot also seems to be too
much for a specific feature like this.
One thing I'm not clear on (patch doesn't include enough detail) is if a
directory url has to come in with a / in order to be considered a request for
a directory. Usually a redirect should be issued if there is a directory
corresponding to the url , like you don't have to put the / on the end shell
directory commands. In other words, you chould do a file command to see if
there is actually a directory corresponding to the request url.
I also don't know where exactly this appears in the request cycle. If you
change the internal URL, you may mess up any registered filters or registered
procs which might be handling this url.
My suggestion is to use a filter to do this as an add on module based upon
ns_rewriteurl. It may not be as fast, but it will be vastly more
configurable.
Test a redirect (triggered by a 'not found' internal redirect and a directory
proc) and info on rewriteurl:
<http://rmadilo.com/files/nsrewrite/doc>
(Note that you could also use the 404 page to do exactly what you want here,
which is to look for another url if the request doesn't exist.)
tom jackson
On Saturday 15 April 2006 08:57, John Buckman wrote:
> On Apr 15, 2006, at 4:07 pm, dhogaza@PACIFIER.COM wrote:
>
> What I was suggesting was a new optional parameter in config.tcl:
>
> ns_param default_ext ".adp"
>
> which would, in the sample-config.tcl file, be commented out and thus
> have no effect. Only if you enable it would this patch take effect.
>
> What I'd like to know is if others would find this feature useful.
>
> -john
>
> ps:
>
> One small bug in what I sent to the list. In case anyone tried to
> compile the change and you're using an older C compiler, you need to
> move the
>
> char * dotpos;
>
> to the top of the function, like so:
>
> static void
> SetUrl(Ns_Request * request, char *url)
> {
> Ns_DString ds1, ds2;
> char *p;
> char * dotpos;
>
> otherwise you'll get a compile time error.
>
> -john
>
>
>
> --
> AOLserver - http://www.aolserver.com/
>
> To Remove yourself from this list, simply send an email to
> <listserv@listserv.aol.com> with the body of "SIGNOFF AOLSERVER" in the
> email message. You can leave the Subject: field of your email blank.
| |
| dhogaza@PACIFIER.COM 2006-04-17, 11:56 pm |
| > Patching the core in this critical spot also seems to be too
> much for a specific feature like this.
Yeah. The major motivation seems to be a belief that it will be
significantly faster than running a simple Tcl filter to do the job. I
would argue that this is precisely the kind of thing filters should be
used for.
> My suggestion is to use a filter to do this as an add on module based upon
> ns_rewriteurl. It may not be as fast, but it will be vastly more
> configurable.
Yep ...
| |
| John Buckman 2006-04-17, 11:56 pm |
| > One thing I'm not clear on (patch doesn't include enough detail) is
> if a
> directory url has to come in with a / in order to be considered a
> request for
> a directory. Usually a redirect should be issued if there is a
> directory
> corresponding to the url , like you don't have to put the / on the
> end shell
> directory commands. In other words, you chould do a file command
> to see if
> there is actually a directory corresponding to the request url.
My patch comes after all the URL logic, which rewrites
http://localhost/dirname
to
http://localhost/dirname/
before my code gets run, so my patch doesn't impact that. That was
very much on purpose.
> I also don't know where exactly this appears in the request cycle.
> If you
> change the internal URL, you may mess up any registered filters or
> registered
> procs which might be handling this url.
My patch happens way at the very beginning, during parsing of the
actual socket data. To filters or anything downstream, it looks like
the user asked for http://localhost/foo.asp rather than http://
localhost/foo and any register filters would need to take that into
account. But, since most existing code would assume the .asp ending
on anything they were interested in (since that's how it works now)
it's unlikely that anyone would be harmed.
> My suggestion is to use a filter to do this as an add on module
> based upon
> ns_rewriteurl. It may not be as fast, but it will be vastly more
> configurable.
Well, I'd probably leave to that someone else then, because fast is
what I need. I'm currently running an online record label
(www.magnatune.com) and get a very heavy load.
But... that's also why I posted the patch to the list. If it doesn't
make it's way into the core, at least someone else may find it useful
and apply the patch the their source.
>
> Test a redirect (triggered by a 'not found' internal redirect and a
> directory
> proc) and info on rewriteurl:
>
> <http://rmadilo.com/files/nsrewrite/doc>
>
> (Note that you could also use the 404 page to do exactly what you
> want here,
> which is to look for another url if the request doesn't exist.)
A 404 would display the .adp to the end-user, which I don't want to
do. Logical URLs such as http://localhost/buy are really nice,
rather than http://localhost/buy.adp, which exposes a technical layer
the end-user shouldn't need to see.
-john
| |
| Tom Jackson 2006-04-17, 11:56 pm |
| On Saturday 15 April 2006 10:07, dhogaza@PACIFIER.COM wrote:
> Yeah. The major motivation seems to be a belief that it will be
> significantly faster than running a simple Tcl filter to do the job. I
> would argue that this is precisely the kind of thing filters should be
> used for.
I also believe that you can write a filter in C, or also a registered proc. If
you look at the code for AOLserver (nsmain.c?), you will find that even the
default page server (what runs if you don't have anything else registered) is
a C module, function, whatever, something like ns_fastpath.... So if C is
faster for a particular application, that is probably the way to do it.
tom jackson
| |
| dhogaza@PACIFIER.COM 2006-04-17, 11:56 pm |
| > Well, I'd probably leave to that someone else then, because fast is
> what I need.
Have you measured the additional overhead of a filter, or are you just
assuming it will be slow?
| |
| Tom Jackson 2006-04-17, 11:56 pm |
| On Saturday 15 April 2006 10:35, John Buckman wrote:
> My patch comes after all the URL logic, which rewrites
> http://localhost/dirname
> to
> http://localhost/dirname/
>
> before my code gets run, so my patch doesn't impact that. That was
> very much on purpose.
>
I don't think this happens, and if it does, it is after the default registered
proc fails to find /dirname. Or if it does happen, I'm wondering why I had to
handle this situation with in every app I've written to do the same thing you
are doing here.
The above situation corresponds to an external redirect, requiring a new
request from the client. You are suggesting that AOLserver is issuing a
redirect prior to any filter or registered procedure has a chance to serve
the request, regardless of what is in pageroot. This is very unlikely, and
would be considered a bug, I think. From this point of view, your patch would
also be considered a bug, although a partially configurable one.
> A 404 would display the .adp to the end-user, which I don't want to
> do. Logical URLs such as http://localhost/buy are really nice,
> rather than http://localhost/buy.adp, which exposes a technical layer
> the end-user shouldn't need to see.
This is not true, an internal redirect does not change the url from the client
point of view. The example I linked to uses a modified directory proc, the
proc is run in a page which handles 404 via an internal redirect. So that
page actually runs twice once for /doc and once for /doc/, since there isn't
a directory file in that directory.
tom jackson
| |
| carl garland 2006-04-17, 11:56 pm |
| 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 <john@MAGNATUNE.COM>
>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
><listserv@listserv.aol.com> with the
>body of "SIGNOFF AOLSERVER" in the email message. You can leave the
>Subject: field of your email blank.
| |
| John Buckman 2006-04-20, 6:55 pm |
| On Apr 17, 2006, at 3:43 PM, carl garland wrote:
> 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.
Yes, that works, I tried that earlier before I made my patch, but:
1) you have to save ADP documents without any filename extension on
the disk, which is weird looking
2) I couldn't make a saved document "index" (rather than index.adp)
work, for whatever reason, so I would have index.adp, but all the
docs in the directory would be w/o an extension.
3) it seems like a big security hole to execute everything and anything
-john
| |
| Nis Jorgensen 2006-04-20, 6:55 pm |
| John Buckman wrote:
> 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.
Disregarding all the other objections, note that the ability to have a
robots.txt.adp, or similar "doubly extended" files, can come in quite
handy. I use it to tell the bots that only the main hostname of my
server should be indexed.
--
Nis Jorgensen Jabber: njorgens@jabber.nli.gl3
GPI ICT Application Developer Yahoo: nizzjorgensen
+31 20 718 2087 ICQ:9005019
|
|
|
|
|