http_handler.erl 532 B

123456789101112131415161718
  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/3]).
  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, cowboy_req:reply(200, Headers, Body, Req), State}.
  12. terminate(_, _, _) ->
  13. ok.