Permalink
Browse files

Add support for init/2 fun in handler

  • Loading branch information...
1 parent fff6996 commit d843a83a9637a4a966bc9b9297261da07c301072 @lafka committed Sep 10, 2012
Showing with 4 additions and 1 deletion.
  1. +4 −1 src/tavern_http.erl
View
@@ -57,7 +57,10 @@ init(_Transport, Req, [Handler]) ->
end
end,
{Req2, State} = lists:foldl( Fun, {Req, #tavern{}}, Defaults),
- {ok, Req2, State#tavern{module = Handler}}.
+ case erlang:function_exported(Handler, init, 2) of
+ true -> Handler:init(Req, State#tavern{module = Handler});
+ false -> {ok, Req2, State#tavern{module = Handler}}
+ end.
-spec handle(Handler :: module(), #http_req{}, #tavern{})-> {ok, #http_req{}, #tavern{}}.
handle(Module, Req, #tavern{} = State) ->

0 comments on commit d843a83

Please sign in to comment.