echo_h.erl 500 B

12345678910111213141516171819
  1. %% This module echoes back the value the test is interested in.
  2. -module(echo_h).
  3. -export([init/2]).
  4. init(Req, Opts) ->
  5. echo(cowboy_req:binding(key, Req), Req, Opts).
  6. echo(What, Req, Opts) ->
  7. F = binary_to_atom(What, latin1),
  8. Value = case cowboy_req:F(Req) of
  9. V when is_integer(V) -> integer_to_binary(V);
  10. V when is_atom(V) -> atom_to_binary(V, latin1);
  11. V when is_list(V); is_tuple(V) -> io_lib:format("~p", [V]);
  12. V -> V
  13. end,
  14. cowboy_req:reply(200, #{}, Value, Req),
  15. {ok, Req, Opts}.