blob: 3ad14fe57b4785fe522df797270a5b6bf59d5df1 [file] [log] [blame]
PiBa-NL05276392018-11-30 21:01:01 +01001
2local vtc_port = 0
3
4core.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")
14end)
15
16local 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
23 local socket = core.tcp()
24 local success = socket:connect("127.0.0.1", vtc_port)
25 core.Info("SOCKET MADE ".. (success or "??"))
26 if success ~= 1 then
27 core.Info("CONNECT SOCKET FAILED?")
28 return
29 end
30 local request = "GET / HTTP/1.1\r\n\r\n"
31 core.Info("SENDING REQUEST")
32 socket:send(request)
33 local result = ""
34 repeat
35 core.Info("4")
36 local d = socket:receive("*a")
37 if d ~= nil then
38 result = result .. d
39 end
40 until d == nil or d == 0
41 core.Info("Received: "..result)
42end
43
44core.register_task(cron)