http_handler.erl 562 B

12345678910111213141516171819
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(http_handler).
  3. -behaviour(cowboy_http_handler).
  4. -export([init/3, handle/2, terminate/2]).
  5. -record(state, {headers, body}).
  6. init({_Transport, http}, Req, Opts) ->
  7. Headers = proplists:get_value(headers, Opts, []),
  8. Body = proplists:get_value(body, Opts, "http_handler"),
  9. {ok, Req, #state{headers=Headers, body=Body}}.
  10. handle(Req, State=#state{headers=Headers, body=Body}) ->
  11. {ok, Req2} = cowboy_http_req:reply(200, Headers, Body, Req),
  12. {ok, Req2, State}.
  13. terminate(_Req, _State) ->
  14. ok.