William Lallemand | 039cc08 | 2021-09-24 19:02:50 +0200 | [diff] [blame] | 1 | |
| 2 | local vtc_port = 0 |
| 3 | |
| 4 | core.register_service("fakeserv", "http", function(applet) |
| 5 | vtc_port = applet.headers["vtcport"][0] |
| 6 | core.Info("APPLET START") |
| 7 | local response = "OK" |
| 8 | applet:add_header("Server", "haproxy/webstats") |
| 9 | applet:add_header("Content-Length", string.len(response)) |
| 10 | applet:add_header("Content-Type", "text/html") |
| 11 | applet:start_response() |
| 12 | applet:send(response) |
| 13 | core.Info("APPLET DONE") |
| 14 | end) |
| 15 | |
| 16 | local function cron() |
| 17 | -- wait for until the correct port is set through the c0 request.. |
| 18 | while vtc_port == 0 do |
| 19 | core.msleep(1) |
| 20 | end |
| 21 | core.Debug('CRON port:' .. vtc_port) |
| 22 | |
William Lallemand | dc2cc90 | 2021-10-26 11:43:26 +0200 | [diff] [blame] | 23 | local body = "" |
| 24 | |
| 25 | for i = 0, 200 do |
| 26 | body = body .. i .. ' ABCDEFGHIJKLMNOPQRSTUVWXYZ\n' |
| 27 | end |
| 28 | |
William Lallemand | 039cc08 | 2021-09-24 19:02:50 +0200 | [diff] [blame] | 29 | local httpclient = core.httpclient() |
William Lallemand | dc2cc90 | 2021-10-26 11:43:26 +0200 | [diff] [blame] | 30 | local response = httpclient:post{url="http://127.0.0.1:" .. vtc_port, body=body} |
William Lallemand | 039cc08 | 2021-09-24 19:02:50 +0200 | [diff] [blame] | 31 | |
| 32 | core.Info("Received: " .. response.body) |
| 33 | end |
| 34 | |
| 35 | core.register_task(cron) |