REGTESTS: lua: test the httpclient:get() feature
This reg-test is heavily inspired by the lua_socket.vtc one. It replaces the HTTP/1.1 request made manually with a socket object with an httpclient object.
This commit is contained in:
parent
7d21836bc6
commit
039cc083ff
|
@ -0,0 +1,29 @@
|
|||
|
||||
local vtc_port = 0
|
||||
|
||||
core.register_service("fakeserv", "http", function(applet)
|
||||
vtc_port = applet.headers["vtcport"][0]
|
||||
core.Info("APPLET START")
|
||||
local response = "OK"
|
||||
applet:add_header("Server", "haproxy/webstats")
|
||||
applet:add_header("Content-Length", string.len(response))
|
||||
applet:add_header("Content-Type", "text/html")
|
||||
applet:start_response()
|
||||
applet:send(response)
|
||||
core.Info("APPLET DONE")
|
||||
end)
|
||||
|
||||
local function cron()
|
||||
-- wait for until the correct port is set through the c0 request..
|
||||
while vtc_port == 0 do
|
||||
core.msleep(1)
|
||||
end
|
||||
core.Debug('CRON port:' .. vtc_port)
|
||||
|
||||
local httpclient = core.httpclient()
|
||||
local response = httpclient:get("http://127.0.0.1:" .. vtc_port)
|
||||
|
||||
core.Info("Received: " .. response.body)
|
||||
end
|
||||
|
||||
core.register_task(cron)
|
|
@ -0,0 +1,34 @@
|
|||
varnishtest "Lua: check httpclient functionality from a lua-task"
|
||||
feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev7)'"
|
||||
feature ignore_unknown_macro
|
||||
|
||||
#REQUIRE_OPTIONS=LUA
|
||||
|
||||
server s1 {
|
||||
rxreq
|
||||
txresp -bodylen 20
|
||||
} -start
|
||||
|
||||
haproxy h1 -conf {
|
||||
global
|
||||
lua-load ${testdir}/lua_httpclient.lua
|
||||
|
||||
frontend fe1
|
||||
mode http
|
||||
bind "fd@${fe1}"
|
||||
default_backend b1
|
||||
|
||||
backend b1
|
||||
mode http
|
||||
http-request use-service lua.fakeserv
|
||||
|
||||
} -start
|
||||
|
||||
client c0 -connect ${h1_fe1_sock} {
|
||||
txreq -url "/" -hdr "vtcport: ${s1_port}"
|
||||
rxresp
|
||||
expect resp.status == 200
|
||||
} -run
|
||||
|
||||
|
||||
server s1 -wait
|
Loading…
Reference in New Issue