asterisk_h.erl 465 B

123456789101112131415161718
  1. %% This module echoes back the value the test is interested in.
  2. -module(asterisk_h).
  3. -export([init/2]).
  4. init(Req, Opts) ->
  5. echo(cowboy_req:header(<<"x-echo">>, Req), Req, Opts).
  6. echo(undefined, Req, Opts) ->
  7. {ok, cowboy_req:reply(200, Req), Opts};
  8. echo(What, Req, Opts) ->
  9. F = binary_to_atom(What, latin1),
  10. Value = case cowboy_req:F(Req) of
  11. V when is_integer(V) -> integer_to_binary(V);
  12. V -> V
  13. end,
  14. {ok, cowboy_req:reply(200, #{}, Value, Req), Opts}.