aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/httptest.lua28
1 files changed, 14 insertions, 14 deletions
diff --git a/test/httptest.lua b/test/httptest.lua
index 61dc60a..a171dd9 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -55,12 +55,12 @@ end
55 55
56local check_request = function(request, expect, ignore) 56local check_request = function(request, expect, ignore)
57 local t 57 local t
58 if not request.sink then 58 if not request.sink then request.sink, t = ltn12.sink.table() end
59 request.sink, t = ltn12.sink.table(t)
60 end
61 request.source = request.source or 59 request.source = request.source or
62 (request.body and ltn12.source.string(request.body)) 60 (request.body and ltn12.source.string(request.body))
63 local response = http.request(request) 61 local response = {}
62 response.code, response.headers, response.status =
63 socket.skip(1, http.request(request))
64 if t and table.getn(t) > 0 then response.body = table.concat(t) end 64 if t and table.getn(t) > 0 then response.body = table.concat(t) end
65 check_result(response, expect, ignore) 65 check_result(response, expect, ignore)
66end 66end
@@ -68,8 +68,8 @@ end
68------------------------------------------------------------------------ 68------------------------------------------------------------------------
69io.write("testing request uri correctness: ") 69io.write("testing request uri correctness: ")
70local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" 70local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string"
71local back, h, c, e = http.get("http://" .. host .. forth) 71local back, c, h = http.request("http://" .. host .. forth)
72if not back then fail(e) end 72if not back then fail(c) end
73back = url.parse(back) 73back = url.parse(back)
74if similar(back.query, "this+is+the+query+string") then print("ok") 74if similar(back.query, "this+is+the+query+string") then print("ok")
75else fail(back.query) end 75else fail(back.query) end
@@ -77,7 +77,7 @@ else fail(back.query) end
77------------------------------------------------------------------------ 77------------------------------------------------------------------------
78io.write("testing query string correctness: ") 78io.write("testing query string correctness: ")
79forth = "this+is+the+query+string" 79forth = "this+is+the+query+string"
80back = http.get("http://" .. host .. cgiprefix .. 80back = http.request("http://" .. host .. cgiprefix ..
81 "/query-string?" .. forth) 81 "/query-string?" .. forth)
82if similar(back, forth) then print("ok") 82if similar(back, forth) then print("ok")
83else fail("failed!") end 83else fail("failed!") end
@@ -153,7 +153,7 @@ check_request(request, expect, ignore)
153 153
154------------------------------------------------------------------------ 154------------------------------------------------------------------------
155io.write("testing simple post function: ") 155io.write("testing simple post function: ")
156back = http.post("http://" .. host .. cgiprefix .. "/cat", index) 156back = http.request("http://" .. host .. cgiprefix .. "/cat", index)
157assert(back == index) 157assert(back == index)
158 158
159------------------------------------------------------------------------ 159------------------------------------------------------------------------
@@ -378,19 +378,19 @@ check_request(request, expect, ignore)
378 378
379------------------------------------------------------------------------ 379------------------------------------------------------------------------
380local body 380local body
381io.write("testing simple get function: ") 381io.write("testing simple request function: ")
382body = http.get("http://" .. host .. prefix .. "/index.html") 382body = http.request("http://" .. host .. prefix .. "/index.html")
383assert(body == index) 383assert(body == index)
384print("ok") 384print("ok")
385 385
386------------------------------------------------------------------------ 386------------------------------------------------------------------------
387io.write("testing HEAD method: ") 387io.write("testing HEAD method: ")
388http.TIMEOUT = 1 388http.TIMEOUT = 1
389response = http.request { 389local r, c, h = http.request {
390 method = "HEAD", 390 method = "HEAD",
391 url = "http://www.cs.princeton.edu/~diego/" 391 url = "http://www.cs.princeton.edu/~diego/"
392} 392}
393assert(response and response.headers) 393assert(r and h and c == 200)
394print("ok") 394print("ok")
395 395
396------------------------------------------------------------------------ 396------------------------------------------------------------------------
@@ -398,7 +398,7 @@ io.write("testing host not found: ")
398local c, e = socket.connect("wronghost", 80) 398local c, e = socket.connect("wronghost", 80)
399local r, re = http.request{url = "http://wronghost/does/not/exist"} 399local r, re = http.request{url = "http://wronghost/does/not/exist"}
400assert(r == nil and e == re) 400assert(r == nil and e == re)
401r, re = http.get("http://wronghost/does/not/exist") 401r, re = http.request("http://wronghost/does/not/exist")
402assert(r == nil and e == re) 402assert(r == nil and e == re)
403print("ok") 403print("ok")
404 404
@@ -407,7 +407,7 @@ io.write("testing invalid url: ")
407local c, e = socket.connect("", 80) 407local c, e = socket.connect("", 80)
408local r, re = http.request{url = host .. prefix} 408local r, re = http.request{url = host .. prefix}
409assert(r == nil and e == re) 409assert(r == nil and e == re)
410r, re = http.get(host .. prefix) 410r, re = http.request(host .. prefix)
411assert(r == nil and e == re) 411assert(r == nil and e == re)
412print("ok") 412print("ok")
413 413