blob: b5a5180c12a9544e66d969b120cfc45024edbc20 [file] [log] [blame]
William Lallemand039cc082021-09-24 19:02:50 +02001
2local vtc_port = 0
William Lallemand207f0cb2021-10-28 15:57:33 +02003local vtc_port2 = 0
William Lallemandf03b53c2021-11-24 15:38:17 +01004local vtc_port3 = 0
William Lallemand039cc082021-09-24 19:02:50 +02005
6core.register_service("fakeserv", "http", function(applet)
7 vtc_port = applet.headers["vtcport"][0]
William Lallemand207f0cb2021-10-28 15:57:33 +02008 vtc_port2 = applet.headers["vtcport2"][0]
William Lallemandf03b53c2021-11-24 15:38:17 +01009 vtc_port3 = applet.headers["vtcport3"][0]
William Lallemand039cc082021-09-24 19:02:50 +020010 core.Info("APPLET START")
11 local response = "OK"
12 applet:add_header("Server", "haproxy/webstats")
13 applet:add_header("Content-Length", string.len(response))
14 applet:add_header("Content-Type", "text/html")
15 applet:start_response()
16 applet:send(response)
17 core.Info("APPLET DONE")
18end)
19
20local function cron()
21 -- wait for until the correct port is set through the c0 request..
22 while vtc_port == 0 do
23 core.msleep(1)
24 end
25 core.Debug('CRON port:' .. vtc_port)
26
William Lallemanddc2cc902021-10-26 11:43:26 +020027 local body = ""
28
William Lallemand207f0cb2021-10-28 15:57:33 +020029 for i = 0, 2000 do
William Lallemanddc2cc902021-10-26 11:43:26 +020030 body = body .. i .. ' ABCDEFGHIJKLMNOPQRSTUVWXYZ\n'
31 end
William Lallemand207f0cb2021-10-28 15:57:33 +020032 core.Info("First httpclient request")
William Lallemand039cc082021-09-24 19:02:50 +020033 local httpclient = core.httpclient()
William Lallemanddc2cc902021-10-26 11:43:26 +020034 local response = httpclient:post{url="http://127.0.0.1:" .. vtc_port, body=body}
William Lallemand039cc082021-09-24 19:02:50 +020035 core.Info("Received: " .. response.body)
William Lallemand207f0cb2021-10-28 15:57:33 +020036
37 body = response.body
38
39 core.Info("Second httpclient request")
40 local httpclient2 = core.httpclient()
41 local response2 = httpclient2:post{url="http://127.0.0.1:" .. vtc_port2, body=body}
42
William Lallemandf03b53c2021-11-24 15:38:17 +010043 core.Info("Third httpclient request")
44 local httpclient3 = core.httpclient()
William Lallemand4f4f2b72022-02-17 20:00:23 +010045 local response3 = httpclient3:get{url="http://127.0.0.1", dst = vtc_port3, headers={ [ "Host" ] = { "foobar.haproxy.local" } }}
William Lallemandf03b53c2021-11-24 15:38:17 +010046
William Lallemand039cc082021-09-24 19:02:50 +020047end
48
49core.register_task(cron)