blob: a79dfb2d15e610af5de7729b758c239d66d3e04f [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 Lallemand039cc082021-09-24 19:02:50 +02004
5core.register_service("fakeserv", "http", function(applet)
6 vtc_port = applet.headers["vtcport"][0]
William Lallemand207f0cb2021-10-28 15:57:33 +02007 vtc_port2 = applet.headers["vtcport2"][0]
William Lallemand039cc082021-09-24 19:02:50 +02008 core.Info("APPLET START")
9 local response = "OK"
10 applet:add_header("Server", "haproxy/webstats")
11 applet:add_header("Content-Length", string.len(response))
12 applet:add_header("Content-Type", "text/html")
13 applet:start_response()
14 applet:send(response)
15 core.Info("APPLET DONE")
16end)
17
18local function cron()
19 -- wait for until the correct port is set through the c0 request..
20 while vtc_port == 0 do
21 core.msleep(1)
22 end
23 core.Debug('CRON port:' .. vtc_port)
24
William Lallemanddc2cc902021-10-26 11:43:26 +020025 local body = ""
26
William Lallemand207f0cb2021-10-28 15:57:33 +020027 for i = 0, 2000 do
William Lallemanddc2cc902021-10-26 11:43:26 +020028 body = body .. i .. ' ABCDEFGHIJKLMNOPQRSTUVWXYZ\n'
29 end
William Lallemand207f0cb2021-10-28 15:57:33 +020030 core.Info("First httpclient request")
William Lallemand039cc082021-09-24 19:02:50 +020031 local httpclient = core.httpclient()
William Lallemanddc2cc902021-10-26 11:43:26 +020032 local response = httpclient:post{url="http://127.0.0.1:" .. vtc_port, body=body}
William Lallemand039cc082021-09-24 19:02:50 +020033 core.Info("Received: " .. response.body)
William Lallemand207f0cb2021-10-28 15:57:33 +020034
35 body = response.body
36
37 core.Info("Second httpclient request")
38 local httpclient2 = core.httpclient()
39 local response2 = httpclient2:post{url="http://127.0.0.1:" .. vtc_port2, body=body}
40
William Lallemand039cc082021-09-24 19:02:50 +020041end
42
43core.register_task(cron)