Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for init/2 fun in handler

  • Loading branch information...
commit d843a83a9637a4a966bc9b9297261da07c301072 1 parent fff6996
@lafka authored
Showing with 4 additions and 1 deletion.
  1. +4 −1 src/tavern_http.erl
View
5 src/tavern_http.erl
@@ -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.
Something went wrong with that request. Please try again.