diff --git a/test/httptest.lua b/test/httptest.lua index 8b84f84..1eb4b6a 100644 --- a/test/httptest.lua +++ b/test/httptest.lua @@ -49,26 +49,26 @@ local request, response, ignore, expect, index, prefix, cgiprefix local t = socket._time() -HOST = HOST or "localhost" +host = host or "localhost" prefix = prefix or "/luasocket" cgiprefix = cgiprefix or "/luasocket/cgi" index = readfile("test/index.html") io.write("testing request uri correctness: ") local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" -local back = socket.http.get("http://" .. HOST .. forth) +local back = socket.http.get("http://" .. host .. forth) if similar(back, forth) then print("ok") else fail("failed!") end io.write("testing query string correctness: ") forth = "this+is+the+query+string" -back = socket.http.get("http://" .. HOST .. cgiprefix .. "/query-string?" .. forth) +back = socket.http.get("http://" .. host .. cgiprefix .. "/query-string?" .. forth) if similar(back, forth) then print("ok") else fail("failed!") end io.write("testing document retrieval: ") request = { - url = "http://" .. HOST .. prefix .. "/index.html" + url = "http://" .. host .. prefix .. "/index.html" } expect = { body = index, @@ -82,7 +82,7 @@ check_request(request, expect, ignore) io.write("testing http redirection: ") request = { - url = "http://" .. HOST .. prefix + url = "http://" .. host .. prefix } expect = { body = index, @@ -97,7 +97,7 @@ check_request(request, expect, ignore) io.write("testing automatic auth failure: ") request = { - url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html" + url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html" } expect = { code = 401 @@ -111,7 +111,7 @@ check_request(request, expect, ignore) io.write("testing http redirection failure: ") request = { - url = "http://" .. HOST .. prefix, + url = "http://" .. host .. prefix, stay = 1 } expect = { @@ -137,7 +137,7 @@ check_request(request, expect, ignore) io.write("testing invalid url: ") request = { - url = HOST .. prefix + url = host .. prefix } local c, e = socket.connect("", 80) expect = { @@ -148,7 +148,7 @@ check_request(request, expect, ignore) io.write("testing document not found: ") request = { - url = "http://" .. HOST .. "/wrongdocument.html" + url = "http://" .. host .. "/wrongdocument.html" } expect = { code = 404 @@ -162,7 +162,7 @@ check_request(request, expect, ignore) io.write("testing auth failure: ") request = { - url = "http://" .. HOST .. prefix .. "/auth/index.html" + url = "http://" .. host .. prefix .. "/auth/index.html" } expect = { code = 401 @@ -176,7 +176,7 @@ check_request(request, expect, ignore) io.write("testing manual basic auth: ") request = { - url = "http://" .. HOST .. prefix .. "/auth/index.html", + url = "http://" .. host .. prefix .. "/auth/index.html", headers = { authorization = "Basic " .. socket.code.base64("luasocket:password") } @@ -193,7 +193,7 @@ check_request(request, expect, ignore) io.write("testing automatic basic auth: ") request = { - url = "http://luasocket:password@" .. HOST .. prefix .. "/auth/index.html" + url = "http://luasocket:password@" .. host .. prefix .. "/auth/index.html" } expect = { code = 200, @@ -207,7 +207,7 @@ check_request(request, expect, ignore) io.write("testing auth info overriding: ") request = { - url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", + url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html", user = "luasocket", password = "password" } @@ -223,7 +223,7 @@ check_request(request, expect, ignore) io.write("testing cgi output retrieval (probably chunked...): ") request = { - url = "http://" .. HOST .. cgiprefix .. "/cat-index-html" + url = "http://" .. host .. cgiprefix .. "/cat-index-html" } expect = { body = index, @@ -237,7 +237,7 @@ check_request(request, expect, ignore) io.write("testing redirect loop: ") request = { - url = "http://" .. HOST .. cgiprefix .. "/redirect-loop" + url = "http://" .. host .. cgiprefix .. "/redirect-loop" } expect = { code = 302 @@ -251,7 +251,7 @@ check_request(request, expect, ignore) io.write("testing post method: ") request = { - url = "http://" .. HOST .. cgiprefix .. "/cat", + url = "http://" .. host .. cgiprefix .. "/cat", method = "POST", body = index } @@ -267,7 +267,7 @@ check_request(request, expect, ignore) io.write("testing wrong scheme: ") request = { - url = "wrong://" .. HOST .. cgiprefix .. "/cat", + url = "wrong://" .. host .. cgiprefix .. "/cat", method = "GET" } expect = { @@ -279,24 +279,24 @@ check_request(request, expect, ignore) local body io.write("testing simple get function: ") -body = socket.http.get("http://" .. HOST .. prefix .. "/index.html") +body = socket.http.get("http://" .. host .. prefix .. "/index.html") check(body == index) io.write("testing simple get function with table args: ") body = socket.http.get { - url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", + url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html", user = "luasocket", password = "password" } check(body == index) io.write("testing simple post function: ") -body = socket.http.post("http://" .. HOST .. cgiprefix .. "/cat", index) +body = socket.http.post("http://" .. host .. cgiprefix .. "/cat", index) check(body == index) io.write("testing simple post function with table args: ") body = socket.http.post { - url = "http://" .. HOST .. cgiprefix .. "/cat", + url = "http://" .. host .. cgiprefix .. "/cat", body = index } check(body == index)