http_req_attr.erl 489 B

123456789101112131415161718
  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 := Attr} = cowboy_req:match_qs(Req, [attr]),
  7. {ok, Req, Attr}.
  8. handle(Req, <<"host_and_port">> = Attr) ->
  9. Host = cowboy_req:host(Req),
  10. Port = cowboy_req:port(Req),
  11. Value = [Host, "\n", integer_to_list(Port)],
  12. {ok, cowboy_req:reply(200, [], Value, Req), Attr}.
  13. terminate(_, _, _) ->
  14. ok.