Skip to content

Commit

Permalink
Added X-Accel-Redirect behaviour for http_router handler
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlapshin committed Nov 15, 2011
1 parent fe590b2 commit f435df4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/cowboy_rack_handler.erl
Expand Up @@ -18,6 +18,7 @@

-export([init/3, handle/2, terminate/2]).
-export([handle/3]).
-include("log.hrl").

-record(state, {
path
Expand Down Expand Up @@ -46,12 +47,19 @@ translate_headers(Headers) ->
[{list_to_binary(Name), V}|Acc]
end, [], Headers).

handle(Req, _Env, Path) ->
handle(Req, Env, Path) ->
case file:read_file_info(filename:join(Path, "config.ru")) of
{ok, _} ->
% ?D({rack_call,Env}),
{ok, {Status, ReplyHeaders, ReplyBody}, Req1} = handle(Req, Path),
{ok, Req2} = cowboy_http_req:reply(Status, ReplyHeaders, ReplyBody, Req1),
{ok, Req2};
case proplists:get_value(<<"X-Accel-Redirect">>, ReplyHeaders) of
undefined ->
{ok, Req2} = cowboy_http_req:reply(Status, ReplyHeaders, ReplyBody, Req1),
{ok, Req2};
Redirect ->
% ?D({rack_redirect,Redirect}),
{unhandled, Req, lists:keystore(path, 1, Env, {path, Redirect})}
end;
{error, _} ->
unhandled
end.
Expand Down
1 change: 1 addition & 0 deletions src/log.hrl
@@ -0,0 +1 @@
-define(D(X), (case application:get_env(rack, logging_function) of undefined -> io:format("~p:~p ~240p~n", [?MODULE, ?LINE, X]); _ -> (element(2,application:get_env(rack,logging_function)))(?MODULE, ?LINE, X) end)).

0 comments on commit f435df4

Please sign in to comment.