Skip to content

Commit

Permalink
Allow platform-specific file serving
Browse files Browse the repository at this point in the history
  • Loading branch information
hntrmrrs committed Nov 21, 2009
1 parent e326ccf commit d9929f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/ewgi.hrl
Expand Up @@ -64,8 +64,8 @@
%% @type ewgi_status() = {integer(), string()}
-type ewgi_status() :: {integer(), string()}.

%% @type ewgi_message_body() = binary() | iolist() | stream()
-type ewgi_message_body() :: binary() | iolist() | stream().
%% @type ewgi_message_body() = binary() | iolist() | stream() | {'file', string()}
-type ewgi_message_body() :: binary() | iolist() | stream() | {'file', string()}.

%% @type ewgi_header_list() = [{ewgi_header_key(), ewgi_header_val()}]
-type ewgi_header_list() :: [{ewgi_header_key(), ewgi_header_val()}].
Expand Down
5 changes: 4 additions & 1 deletion src/server_gateways/ewgi_mochiweb.erl
Expand Up @@ -31,10 +31,13 @@ req(MochiReq, Opts) ->

-spec rsp(MochiReq::tuple(), Opts::list(), Rsp::#ewgi_rsp{}) -> 'ok' | {'error', any()}.

rsp(MochiReq, _Opts, Rsp) when is_record(Rsp, ewgi_rsp) ->
rsp(MochiReq, Opts, Rsp) when is_record(Rsp, ewgi_rsp) ->
{Code, _Msg} = ewgi:status(Rsp),
Headers = ewgi:rsp_headers(Rsp),
case ewgi:body(Rsp) of
{file, Path} when is_list(Path) ->
DocRoot = proplists:get_value(docroot, Opts, []),
MochiReq:serve_file(Path, DocRoot, Headers);
F when is_function(F, 0) ->
% Stream returned, so chunk response
% XXX: This should only be allowed for HTTP/1.1 requests
Expand Down

0 comments on commit d9929f7

Please sign in to comment.