http_req_attr.erl 527 B

12345678910111213141516171819
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(http_req_attr).
  3. -behaviour(cowboy_http_handler).
  4. -export([init/3, handle/2, terminate/3]).
  5. init({_, http}, Req, _) ->
  6. {Attr, Req2} = cowboy_req:qs_val(<<"attr">>, Req),
  7. {ok, Req2, Attr}.
  8. handle(Req, <<"host_and_port">> = Attr) ->
  9. {Host, Req2} = cowboy_req:host(Req),
  10. {Port, Req3} = cowboy_req:port(Req2),
  11. Value = [Host, "\n", integer_to_list(Port)],
  12. {ok, Req4} = cowboy_req:reply(200, [], Value, Req3),
  13. {ok, Req4, Attr}.
  14. terminate(_, _, _) ->
  15. ok.