Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 46 lines (36 sloc) 1.159 kb
c6b257c @trung added mochiweb server to capture amf requests
authored
1 %% @author author <author@example.com>
2 %% @copyright YYYY author.
3
4 %% @doc Web server for erling_server.
5
6 -module(erling_server_web).
7 -author('author <author@example.com>').
8
9 -export([start/1, stop/0, loop/2]).
10
11 %% External API
12
13 start(Options) ->
14 {DocRoot, Options1} = get_option(docroot, Options),
15 Loop = fun (Req) ->
16 ?MODULE:loop(Req, DocRoot)
17 end,
18 mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options1]).
19
20 stop() ->
21 mochiweb_http:stop(?MODULE).
22
23 loop(Req, DocRoot) ->
24 "/" ++ Path = Req:get(path),
25 io:format("Path = [~p]", [Path]),
26 case Req:get(method) of
27 Method when Method =:= 'GET'; Method =:= 'HEAD' ->
28 case Path of
29 _ ->
30 Req:serve_file(Path, DocRoot)
31 end;
32 'POST' ->
33 io:format("Body = [~p]", [Req:recv_body()]),
34 case Path of
35 _ ->
36 Req:not_found()
37 end;
38 _ ->
39 Req:respond({501, [], []})
40 end.
41
42 %% Internal API
43
44 get_option(Option, Options) ->
45 {proplists:get_value(Option, Options), proplists:delete(Option, Options)}.
Something went wrong with that request. Please try again.