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