Skip to content

Commit

Permalink
Add static file support to mochiweb.
Browse files Browse the repository at this point in the history
  • Loading branch information
rustyio committed Sep 10, 2009
1 parent 6ac7b79 commit c47e995
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/mochiweb_bridge_modules/mochiweb_request_bridge.erl
Expand Up @@ -15,38 +15,38 @@

-define(PRINT(Var), error_logger:info_msg("DEBUG: ~p:~p - ~p: ~p~n", [?MODULE, ?LINE, ??Var, Var])).

init(Req) ->
Req.
init({Req, DocRoot}) ->
{Req, DocRoot}.

request_method(Req) ->
request_method({Req, _DocRoot}) ->
Req:get(method).

path(Req) ->
path({Req, _DocRoot}) ->
RawPath = Req:get(raw_path),
{Path, _, _} = mochiweb_util:urlsplit_path(RawPath),
Path.

peer_ip(Req) ->
peer_ip({Req, _DocRoot}) ->
Socket = Req:get(socket),
{ok, {IP, _Port}} = inet:peername(Socket),
IP.

peer_port(Req) ->
peer_port({Req, _DocRoot}) ->
Socket = Req:get(socket),
{ok, {_IP, Port}} = inet:peername(Socket),
Port.

headers(Req) ->
headers({Req, _DocRoot}) ->
Req:get(headers).

cookies(Req) ->
cookies({Req, _DocRoot}) ->
Req:parse_cookie().

query_params(Req) ->
query_params({Req, _DocRoot}) ->
Req:parse_qs().

post_params(Req) ->
post_params({Req, _DocRoot}) ->
Req:parse_post().

request_body(_Req) ->
request_body({_Req, _DocRoot}) ->
[].
6 changes: 3 additions & 3 deletions src/mochiweb_bridge_modules/mochiweb_response_bridge.erl
Expand Up @@ -7,7 +7,7 @@
-include ("simplebridge.hrl").
-export ([build_response/2]).

build_response(Req, Res) ->
build_response({Req, DocRoot}, Res) ->
% Some values...
Code = Res#response.statuscode,
case Res#response.data of
Expand All @@ -21,8 +21,8 @@ build_response(Req, Res) ->

% Send the mochiweb response...
Req:respond({Code, Headers, Body});
{file, _File} ->
throw(not_supported)
{file, Path} ->
Req:serve_file(tl(Path), DocRoot)
end.

create_cookie_header(Cookie) ->
Expand Down

0 comments on commit c47e995

Please sign in to comment.