William Lallemand | 039cc08 | 2021-09-24 19:02:50 +0200 | [diff] [blame] | 1 | |
| 2 | local vtc_port = 0 |
William Lallemand | 207f0cb | 2021-10-28 15:57:33 +0200 | [diff] [blame] | 3 | local vtc_port2 = 0 |
William Lallemand | f03b53c | 2021-11-24 15:38:17 +0100 | [diff] [blame] | 4 | local vtc_port3 = 0 |
William Lallemand | 039cc08 | 2021-09-24 19:02:50 +0200 | [diff] [blame] | 5 | |
| 6 | core.register_service("fakeserv", "http", function(applet) |
| 7 | vtc_port = applet.headers["vtcport"][0] |
William Lallemand | 207f0cb | 2021-10-28 15:57:33 +0200 | [diff] [blame] | 8 | vtc_port2 = applet.headers["vtcport2"][0] |
William Lallemand | f03b53c | 2021-11-24 15:38:17 +0100 | [diff] [blame] | 9 | vtc_port3 = applet.headers["vtcport3"][0] |
William Lallemand | 039cc08 | 2021-09-24 19:02:50 +0200 | [diff] [blame] | 10 | 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") |
| 18 | end) |
| 19 | |
| 20 | local 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 Lallemand | dc2cc90 | 2021-10-26 11:43:26 +0200 | [diff] [blame] | 27 | local body = "" |
| 28 | |
William Lallemand | 207f0cb | 2021-10-28 15:57:33 +0200 | [diff] [blame] | 29 | for i = 0, 2000 do |
William Lallemand | dc2cc90 | 2021-10-26 11:43:26 +0200 | [diff] [blame] | 30 | body = body .. i .. ' ABCDEFGHIJKLMNOPQRSTUVWXYZ\n' |
| 31 | end |
William Lallemand | 207f0cb | 2021-10-28 15:57:33 +0200 | [diff] [blame] | 32 | core.Info("First httpclient request") |
William Lallemand | 039cc08 | 2021-09-24 19:02:50 +0200 | [diff] [blame] | 33 | local httpclient = core.httpclient() |
William Lallemand | dc2cc90 | 2021-10-26 11:43:26 +0200 | [diff] [blame] | 34 | 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] | 35 | core.Info("Received: " .. response.body) |
William Lallemand | 207f0cb | 2021-10-28 15:57:33 +0200 | [diff] [blame] | 36 | |
| 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 Lallemand | f03b53c | 2021-11-24 15:38:17 +0100 | [diff] [blame] | 43 | core.Info("Third httpclient request") |
| 44 | local httpclient3 = core.httpclient() |
William Lallemand | 4f4f2b7 | 2022-02-17 20:00:23 +0100 | [diff] [blame] | 45 | local response3 = httpclient3:get{url="http://127.0.0.1", dst = vtc_port3, headers={ [ "Host" ] = { "foobar.haproxy.local" } }} |
William Lallemand | f03b53c | 2021-11-24 15:38:17 +0100 | [diff] [blame] | 46 | |
William Lallemand | 039cc08 | 2021-09-24 19:02:50 +0200 | [diff] [blame] | 47 | end |
| 48 | |
| 49 | core.register_task(cron) |