Compiled in WinXP

This commit is contained in:
Diego Nehab 2003-03-28 22:41:26 +00:00
parent 335cdbf334
commit 4755ad727e

View File

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