aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_SUITE_data/http_req_attr.erl
blob: 2a4a55db2af1e6ccb70139f10f91a56ea340c66d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
%% Feel free to use, reuse and abuse the code in this file.

-module(http_req_attr).
-behaviour(cowboy_http_handler).
-export([init/3, handle/2, terminate/3]).

init({_, http}, Req, _) ->
	#{attr := Attr} = cowboy_req:match_qs(Req, [attr]),
	{ok, Req, Attr}.

handle(Req, <<"host_and_port">> = Attr) ->
	Host = cowboy_req:host(Req),
	Port = cowboy_req:port(Req),
	Value = [Host, "\n", integer_to_list(Port)],
	{ok, cowboy_req:reply(200, [], Value, Req), Attr}.

terminate(_, _, _) ->
	ok.