Appmods are a way to let the application programmer take control over the URL path. Or put in another way, to let the application programmer fake real paths in URLs where in reality an Erlang modules is executing. Possibly an example make this easy to understand. Say we have the folowing url
http://yaws.hyber.org/pathelem/foo/bar/x.pdf
With the above url, the webserver would try to deliver the file "foo/bar/x.pdf" relative to the docroot. However if we had specified "pathelem" as an appmod, the server would stop processing the url after seeing the "pathelem" part of the URL. Say we had the following in our yaws.conf configuration file
<server tita>
port = 8001
listen = 0.0.0.0
docroot = /home/klacke/yaws/yaws/scripts/../www
appmods = <pathelem, myappmod>
</server>Then the webserver would invoke myappmod:out(A) instead of trying to deliver the actual file. When shipping such an Url there are 2 fields in the #arg record which are especially interesting. If we have the following code in "myappmod.erl":
-module(myappmod).
-author('klacke@bluetail.com').
-include("../../include/yaws_api.hrl").
-compile(export_all).
box(Str) ->
{'div',[{class,"box"}],
{pre,[],Str}}.
out(A) ->
{ehtml,
[{p,[],
box(io_lib:format("A#arg.appmoddata = ~p~n"
"A#arg.appmod_prepath = ~p~n"
"A#arg.querydata = ~p~n",
[A#arg.appmoddata,
A#arg.appmod_prepath,
A#arg.querydata]))}]}.
The #arg field called "appmoddata" contains the remainder of the path following the encountered appmod and the field "appmod_prepath" contains the part of the URL path leading upto the appmod.
Thus the following url
http://yaws.hyber.org/zap/pathelem/foo/bar/x.pdf?a=b
Produces the following output:
A#arg.appmoddata = "/foo/bar/x.pdf" A#arg.appmod_prepath = "/zap/" A#arg.querydata = "a=b"
Appmods would typically be used by webapplications that want to provide the illusion of proper paths to the browser.