summaryrefslogtreecommitdiff
path: root/deps/mochiweb/priv/skel/src/skel_web.erl
diff options
context:
space:
mode:
Diffstat (limited to 'deps/mochiweb/priv/skel/src/skel_web.erl')
-rw-r--r--deps/mochiweb/priv/skel/src/skel_web.erl51
1 files changed, 51 insertions, 0 deletions
diff --git a/deps/mochiweb/priv/skel/src/skel_web.erl b/deps/mochiweb/priv/skel/src/skel_web.erl
new file mode 100644
index 00000000..67064cc5
--- /dev/null
+++ b/deps/mochiweb/priv/skel/src/skel_web.erl
@@ -0,0 +1,51 @@
+%% @author author <author@example.com>
+%% @copyright YYYY author.
+
+%% @doc Web server for skel.
+
+-module(skel_web).
+-author('author <author@example.com>').
+
+-export([start/1, stop/0, loop/2]).
+
+%% External API
+
+start(Options) ->
+ {DocRoot, Options1} = get_option(docroot, Options),
+ Loop = fun (Req) ->
+ ?MODULE:loop(Req, DocRoot)
+ end,
+ mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options1]).
+
+stop() ->
+ mochiweb_http:stop(?MODULE).
+
+loop(Req, DocRoot) ->
+ "/" ++ Path = Req:get(path),
+ case Req:get(method) of
+ Method when Method =:= 'GET'; Method =:= 'HEAD' ->
+ case Path of
+ _ ->
+ Req:serve_file(Path, DocRoot)
+ end;
+ 'POST' ->
+ case Path of
+ _ ->
+ Req:not_found()
+ end;
+ _ ->
+ Req:respond({501, [], []})
+ end.
+
+%% Internal API
+
+get_option(Option, Options) ->
+ {proplists:get_value(Option, Options), proplists:delete(Option, Options)}.
+
+
+%%
+%% Tests
+%%
+-include_lib("eunit/include/eunit.hrl").
+-ifdef(TEST).
+-endif.