Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add support for init/2 fun in handler

  • Loading branch information...
commit d843a83a9637a4a966bc9b9297261da07c301072 1 parent fff6996
authored

Showing 1 changed file with 4 additions and 1 deletion. Show diff stats Hide diff stats

  1. +4 1 src/tavern_http.erl
5 src/tavern_http.erl
@@ -57,7 +57,10 @@ init(_Transport, Req, [Handler]) ->
57 57 end
58 58 end,
59 59 {Req2, State} = lists:foldl( Fun, {Req, #tavern{}}, Defaults),
60   - {ok, Req2, State#tavern{module = Handler}}.
  60 + case erlang:function_exported(Handler, init, 2) of
  61 + true -> Handler:init(Req, State#tavern{module = Handler});
  62 + false -> {ok, Req2, State#tavern{module = Handler}}
  63 + end.
61 64
62 65 -spec handle(Handler :: module(), #http_req{}, #tavern{})-> {ok, #http_req{}, #tavern{}}.
63 66 handle(Module, Req, #tavern{} = State) ->

0 comments on commit d843a83

Please sign in to comment.
Something went wrong with that request. Please try again.