Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

documented appmods as an example

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@687 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
commit e7aa877133c514188053e154a9c2a77dfcae9dd0 1 parent b67bbd8
Claes Wikstrom authored
2  Makefile
View
@@ -1,5 +1,5 @@
-SUBDIRS = c_src src man www/shopingcart doc scripts
+SUBDIRS = c_src src man www/shopingcart www/code doc scripts
include ./include.mk
7 src/yaws_server.erl
View
@@ -2550,8 +2550,9 @@ do_url_type(SC, GetPath) ->
end;
{ok, Head, {PathElem, Mod}, Trail} ->
#urltype{type = appmod,
- data = {Mod, conc_path(Head)},
- path = conc_path(Trail)}
+ data = {Mod, [$/ | conc_path(Trail) ++
+ lists:reverse(RevFile)]},
+ path = conc_path(Head)}
end
end.
@@ -2603,7 +2604,7 @@ split_at(AM={PE, Mod}, [PEslash|Tail], Ack) ->
true ->
{ok, lists:reverse(Ack), AM, Tail};
false ->
- split_at(AM, Tail, [PE|Ack])
+ split_at(AM, Tail, [PEslash|Ack])
end.
1  www/EXHEAD
View
@@ -20,6 +20,7 @@
<td> <A HREF="/cookies.yaws">Cookies</a> </td>
<td> <A HREF="/pcookie.yaws">Persistent Cookies</a> </td>
<td> <A HREF="/session.yaws">Cookie sessions</a> </td>
+ <td> <A HREF="/appmods.yaws">Appmods</a> </td>
<td> <A HREF="/shopingcart/index.yaws">Tiny shopping cart</a> </td>
<td> <A HREF="/embed.yaws">Embedding Yaws</a> </td>
85 www/appmods.yaws
View
@@ -0,0 +1,85 @@
+
+<erl>
+
+
+box(Str) ->
+ {'div',[{class,"box"}],
+ {pre,[],Str}}.
+
+tbox(T) ->
+ box(lists:flatten(io_lib:format("~p",[T]))).
+
+
+ssi(File) ->
+ {'div',[{class,"box"}],
+ {pre,[],
+ {ssi, File,[],[]}}}.
+
+
+out(A) ->
+ [{ssi, "HEAD", [],[]},
+ {ssi, "EXHEAD", [],[]},
+ {ehtml,
+ [{h1, [], "Appmods (Application modules)"},
+
+ {p, [],
+ ["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"]},
+
+ box("http://yaws.hyber.org/pathelem/foo/bar/x.pdf"),
+
+ {p,[],["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"]},
+
+
+ box("
+<server tita>
+ port = 8001
+ listen = 0.0.0.0
+ docroot = /home/klacke/yaws/yaws/scripts/../www
+ appmods = <pathelem, mymod>
+</server>"),
+
+
+
+
+ {p,[],
+ ["Then the webserver would invoke ",
+ {tt,[], "myappmod:out(A)"},
+ " instead of trying to deliver the actual file. When shipping such an ",
+ {a, [{href, "/pathelem/foo/bar/x.pdf"}], "Url"},
+ " there are 2 fields in the #arg record which are especially interesting. If we have the following code in \"myappmod.erl\":"]},
+
+ ssi("code/myappmod.erl"),
+
+ {p,[],"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."},
+
+
+ {p,[],
+ "Thus the following url"},
+ box("http://yaws.hyber.org/zap/pathelem/foo/bar/x.pdf?a=b"),
+ {p,[],
+ "Produces the following output:"},
+ box("
+A#arg.appmoddata = \"/foo/bar/x.pdf\"
+A#arg.appmod_prepath = \"/zap/\"
+A#arg.querydata = \"a=b\""),
+
+ {br},
+
+ {p, [],
+ "Appmods would typically be used by webapplications that want to provide the illusion of proper paths to the browser. "}
+
+
+ ]}].
+
+
+
+</erl>
+
+
+</html>
+
+
+
+
+
+
15 www/code/Makefile
View
@@ -0,0 +1,15 @@
+include ../../include.mk
+
+all: myappmod.beam
+ cp myappmod.beam ../../examples/ebin
+debug:
+
+install: all
+ cp myappmod.beam $(VARDIR)/yaws/ebin
+
+clean:
+ $(RM) myappmod.beam
+ $(RM) ../../examples/ebin/myappmod.beam
+
+myappmod.beam: myappmod.erl
+ erlc myappmod.erl
22 www/code/myappmod.erl
View
@@ -0,0 +1,22 @@
+-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]))}]}.
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.