diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/httptest.lua | 28 |
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 | ||
56 | local check_request = function(request, expect, ignore) | 56 | local 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) |
66 | end | 66 | end |
@@ -68,8 +68,8 @@ end | |||
68 | ------------------------------------------------------------------------ | 68 | ------------------------------------------------------------------------ |
69 | io.write("testing request uri correctness: ") | 69 | io.write("testing request uri correctness: ") |
70 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" | 70 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" |
71 | local back, h, c, e = http.get("http://" .. host .. forth) | 71 | local back, c, h = http.request("http://" .. host .. forth) |
72 | if not back then fail(e) end | 72 | if not back then fail(c) end |
73 | back = url.parse(back) | 73 | back = url.parse(back) |
74 | if similar(back.query, "this+is+the+query+string") then print("ok") | 74 | if similar(back.query, "this+is+the+query+string") then print("ok") |
75 | else fail(back.query) end | 75 | else fail(back.query) end |
@@ -77,7 +77,7 @@ else fail(back.query) end | |||
77 | ------------------------------------------------------------------------ | 77 | ------------------------------------------------------------------------ |
78 | io.write("testing query string correctness: ") | 78 | io.write("testing query string correctness: ") |
79 | forth = "this+is+the+query+string" | 79 | forth = "this+is+the+query+string" |
80 | back = http.get("http://" .. host .. cgiprefix .. | 80 | back = http.request("http://" .. host .. cgiprefix .. |
81 | "/query-string?" .. forth) | 81 | "/query-string?" .. forth) |
82 | if similar(back, forth) then print("ok") | 82 | if similar(back, forth) then print("ok") |
83 | else fail("failed!") end | 83 | else fail("failed!") end |
@@ -153,7 +153,7 @@ check_request(request, expect, ignore) | |||
153 | 153 | ||
154 | ------------------------------------------------------------------------ | 154 | ------------------------------------------------------------------------ |
155 | io.write("testing simple post function: ") | 155 | io.write("testing simple post function: ") |
156 | back = http.post("http://" .. host .. cgiprefix .. "/cat", index) | 156 | back = http.request("http://" .. host .. cgiprefix .. "/cat", index) |
157 | assert(back == index) | 157 | assert(back == index) |
158 | 158 | ||
159 | ------------------------------------------------------------------------ | 159 | ------------------------------------------------------------------------ |
@@ -378,19 +378,19 @@ check_request(request, expect, ignore) | |||
378 | 378 | ||
379 | ------------------------------------------------------------------------ | 379 | ------------------------------------------------------------------------ |
380 | local body | 380 | local body |
381 | io.write("testing simple get function: ") | 381 | io.write("testing simple request function: ") |
382 | body = http.get("http://" .. host .. prefix .. "/index.html") | 382 | body = http.request("http://" .. host .. prefix .. "/index.html") |
383 | assert(body == index) | 383 | assert(body == index) |
384 | print("ok") | 384 | print("ok") |
385 | 385 | ||
386 | ------------------------------------------------------------------------ | 386 | ------------------------------------------------------------------------ |
387 | io.write("testing HEAD method: ") | 387 | io.write("testing HEAD method: ") |
388 | http.TIMEOUT = 1 | 388 | http.TIMEOUT = 1 |
389 | response = http.request { | 389 | local 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 | } |
393 | assert(response and response.headers) | 393 | assert(r and h and c == 200) |
394 | print("ok") | 394 | print("ok") |
395 | 395 | ||
396 | ------------------------------------------------------------------------ | 396 | ------------------------------------------------------------------------ |
@@ -398,7 +398,7 @@ io.write("testing host not found: ") | |||
398 | local c, e = socket.connect("wronghost", 80) | 398 | local c, e = socket.connect("wronghost", 80) |
399 | local r, re = http.request{url = "http://wronghost/does/not/exist"} | 399 | local r, re = http.request{url = "http://wronghost/does/not/exist"} |
400 | assert(r == nil and e == re) | 400 | assert(r == nil and e == re) |
401 | r, re = http.get("http://wronghost/does/not/exist") | 401 | r, re = http.request("http://wronghost/does/not/exist") |
402 | assert(r == nil and e == re) | 402 | assert(r == nil and e == re) |
403 | print("ok") | 403 | print("ok") |
404 | 404 | ||
@@ -407,7 +407,7 @@ io.write("testing invalid url: ") | |||
407 | local c, e = socket.connect("", 80) | 407 | local c, e = socket.connect("", 80) |
408 | local r, re = http.request{url = host .. prefix} | 408 | local r, re = http.request{url = host .. prefix} |
409 | assert(r == nil and e == re) | 409 | assert(r == nil and e == re) |
410 | r, re = http.get(host .. prefix) | 410 | r, re = http.request(host .. prefix) |
411 | assert(r == nil and e == re) | 411 | assert(r == nil and e == re) |
412 | print("ok") | 412 | print("ok") |
413 | 413 | ||