Skip to content

Commit

Permalink
feat: support with cowboy req
Browse files Browse the repository at this point in the history
  • Loading branch information
turtleDeng committed Mar 25, 2024
1 parent 1df1cbb commit 2e9bc88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/minirest.appup.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%%-*-: erlang -*-
{VSN,
[
{<<"0\\.3\\.(11|10|[0-9])">>,
{<<"0\\.3\\.(13|12|11|10|[0-9])">>,
[ {add_module, minirest_utils},
{load_module, minirest, brutal_purge, soft_purge, []},
{load_module, minirest_handler, brutal_purge, soft_purge, []}
Expand All @@ -10,7 +10,7 @@
{<<".*">>, []}
],
[
{<<"0\\.3\\.(11|10|[0-9])">>,
{<<"0\\.3\\.(13|12|11|10|[0-9])">>,
[ {load_module, minirest, brutal_purge, soft_purge, []},
{load_module, minirest_handler, brutal_purge, soft_purge, []},
{delete_module, minirest_utils}
Expand Down
6 changes: 5 additions & 1 deletion src/minirest_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ dispatch(Req, #{module := Mod, func := Fun, bindings := Bindings} = Route) ->
})),
reply(400, <<"Bad Request">>, Req);
Params ->
case erlang:apply(Mod, Fun, [Bindings, Params]) of
Params1 = case maps:get(with_cowboy_req, Route, false) of
true -> [Bindings, Params, Req];
false -> [Bindings, Params, Req]
end,
case erlang:apply(Mod, Fun, Params1) of
{file, Headers, {sendfile, _, _, _} = SendFile} ->
Req1 = cowboy_req:reply(200, Headers, SendFile, Req),
#{pattern := [Type|_], name := Name} = Route,
Expand Down

0 comments on commit 2e9bc88

Please sign in to comment.