diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-03-16 06:42:53 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-03-16 06:42:53 +0000 |
| commit | bcc0c2a9f0be2ca796ef5206a78e283fe15e6186 (patch) | |
| tree | 65c269d4854aa5ff4a0b2c8eede5cdb18d716033 /test/httptest.lua | |
| parent | b6edaac2841137cf0ef5105f75358bbab4570d87 (diff) | |
| download | luasocket-bcc0c2a9f0be2ca796ef5206a78e283fe15e6186.tar.gz luasocket-bcc0c2a9f0be2ca796ef5206a78e283fe15e6186.tar.bz2 luasocket-bcc0c2a9f0be2ca796ef5206a78e283fe15e6186.zip | |
New filter scheme.
ltn12 and mime updated.
smtp/ftp broken.
Diffstat (limited to 'test/httptest.lua')
| -rw-r--r-- | test/httptest.lua | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/test/httptest.lua b/test/httptest.lua index c9a74a8..04c0ed0 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
| @@ -12,7 +12,7 @@ socket.http.TIMEOUT = 5 | |||
| 12 | 12 | ||
| 13 | local t = socket.time() | 13 | local t = socket.time() |
| 14 | 14 | ||
| 15 | host = host or "diego-interface2.student.dyn.CS.Princeton.EDU" | 15 | host = host or "diego.student.princeton.edu" |
| 16 | proxy = proxy or "http://localhost:3128" | 16 | proxy = proxy or "http://localhost:3128" |
| 17 | prefix = prefix or "/luasocket-test" | 17 | prefix = prefix or "/luasocket-test" |
| 18 | cgiprefix = cgiprefix or "/luasocket-test-cgi" | 18 | cgiprefix = cgiprefix or "/luasocket-test-cgi" |
| @@ -71,8 +71,8 @@ local check_request = function(request, expect, ignore) | |||
| 71 | check_result(response, expect, ignore) | 71 | check_result(response, expect, ignore) |
| 72 | end | 72 | end |
| 73 | 73 | ||
| 74 | local check_request_cb = function(request, response, expect, ignore) | 74 | local check_request_cb = function(request, expect, ignore) |
| 75 | local response = socket.http.request_cb(request, response) | 75 | local response = socket.http.request_cb(request) |
| 76 | check_result(response, expect, ignore) | 76 | check_result(response, expect, ignore) |
| 77 | end | 77 | end |
| 78 | 78 | ||
| @@ -83,7 +83,7 @@ local back, h, c, e = socket.http.get("http://" .. host .. forth) | |||
| 83 | if not back then fail(e) end | 83 | if not back then fail(e) end |
| 84 | back = socket.url.parse(back) | 84 | back = socket.url.parse(back) |
| 85 | if similar(back.query, "this+is+the+query+string") then print("ok") | 85 | if similar(back.query, "this+is+the+query+string") then print("ok") |
| 86 | else fail() end | 86 | else fail(back.query) end |
| 87 | 87 | ||
| 88 | ------------------------------------------------------------------------ | 88 | ------------------------------------------------------------------------ |
| 89 | io.write("testing query string correctness: ") | 89 | io.write("testing query string correctness: ") |
| @@ -168,31 +168,28 @@ back = socket.http.post("http://" .. host .. cgiprefix .. "/cat", index) | |||
| 168 | check(back == index) | 168 | check(back == index) |
| 169 | 169 | ||
| 170 | ------------------------------------------------------------------------ | 170 | ------------------------------------------------------------------------ |
| 171 | io.write("testing send.file and receive.file callbacks: ") | 171 | io.write("testing ltn12.(sink|source).file: ") |
| 172 | request = { | 172 | request = { |
| 173 | url = "http://" .. host .. cgiprefix .. "/cat", | 173 | url = "http://" .. host .. cgiprefix .. "/cat", |
| 174 | method = "POST", | 174 | method = "POST", |
| 175 | body_cb = socket.callback.send.file(io.open(index_file, "r")), | 175 | source = ltn12.source.file(io.open(index_file, "r")), |
| 176 | sink = ltn12.sink.file(io.open(index_file .. "-back", "w")), | ||
| 176 | headers = { ["content-length"] = string.len(index) } | 177 | headers = { ["content-length"] = string.len(index) } |
| 177 | } | 178 | } |
| 178 | response = { | ||
| 179 | body_cb = socket.callback.receive.file(io.open(index_file .. "-back", "w")) | ||
| 180 | } | ||
| 181 | expect = { | 179 | expect = { |
| 182 | code = 200 | 180 | code = 200 |
| 183 | } | 181 | } |
| 184 | ignore = { | 182 | ignore = { |
| 185 | body_cb = 1, | ||
| 186 | status = 1, | 183 | status = 1, |
| 187 | headers = 1 | 184 | headers = 1 |
| 188 | } | 185 | } |
| 189 | check_request_cb(request, response, expect, ignore) | 186 | check_request_cb(request, expect, ignore) |
| 190 | back = readfile(index_file .. "-back") | 187 | back = readfile(index_file .. "-back") |
| 191 | check(back == index) | 188 | check(back == index) |
| 192 | os.remove(index_file .. "-back") | 189 | os.remove(index_file .. "-back") |
| 193 | 190 | ||
| 194 | ------------------------------------------------------------------------ | 191 | ------------------------------------------------------------------------ |
| 195 | io.write("testing send.chain and receive.chain callbacks: ") | 192 | io.write("testing ltn12.(sink|source).chain and mime.(encode|decode): ") |
| 196 | 193 | ||
| 197 | local function b64length(len) | 194 | local function b64length(len) |
| 198 | local a = math.ceil(len/3)*4 | 195 | local a = math.ceil(len/3)*4 |
| @@ -200,26 +197,26 @@ local function b64length(len) | |||
| 200 | return a + l*2 | 197 | return a + l*2 |
| 201 | end | 198 | end |
| 202 | 199 | ||
| 203 | local req_cb = socket.callback.send.chain( | 200 | local source = ltn12.source.chain( |
| 204 | socket.callback.send.file(io.open(index_file, "r")), | 201 | ltn12.source.file(io.open(index_file, "r")), |
| 205 | socket.mime.chain( | 202 | ltn12.filter.chain( |
| 206 | socket.mime.encode("base64"), | 203 | mime.encode("base64"), |
| 207 | socket.mime.wrap("base64") | 204 | mime.wrap("base64") |
| 208 | ) | 205 | ) |
| 209 | ) | 206 | ) |
| 210 | 207 | ||
| 211 | local resp_cb = socket.callback.receive.chain( | 208 | local sink = ltn12.sink.chain( |
| 212 | socket.mime.decode("base64"), | 209 | mime.decode("base64"), |
| 213 | socket.callback.receive.file(io.open(index_file .. "-back", "w")) | 210 | ltn12.sink.file(io.open(index_file .. "-back", "w")) |
| 214 | ) | 211 | ) |
| 215 | 212 | ||
| 216 | request = { | 213 | request = { |
| 217 | url = "http://" .. host .. cgiprefix .. "/cat", | 214 | url = "http://" .. host .. cgiprefix .. "/cat", |
| 218 | method = "POST", | 215 | method = "POST", |
| 219 | body_cb = req_cb, | 216 | source = source, |
| 217 | sink = sink, | ||
| 220 | headers = { ["content-length"] = b64length(string.len(index)) } | 218 | headers = { ["content-length"] = b64length(string.len(index)) } |
| 221 | } | 219 | } |
| 222 | response = { body_cb = resp_cb } | ||
| 223 | expect = { | 220 | expect = { |
| 224 | code = 200 | 221 | code = 200 |
| 225 | } | 222 | } |
| @@ -228,7 +225,7 @@ ignore = { | |||
| 228 | status = 1, | 225 | status = 1, |
| 229 | headers = 1 | 226 | headers = 1 |
| 230 | } | 227 | } |
| 231 | check_request_cb(request, response, expect, ignore) | 228 | check_request_cb(request, expect, ignore) |
| 232 | back = readfile(index_file .. "-back") | 229 | back = readfile(index_file .. "-back") |
| 233 | check(back == index) | 230 | check(back == index) |
| 234 | os.remove(index_file .. "-back") | 231 | os.remove(index_file .. "-back") |
| @@ -362,7 +359,7 @@ io.write("testing manual basic auth: ") | |||
| 362 | request = { | 359 | request = { |
| 363 | url = "http://" .. host .. prefix .. "/auth/index.html", | 360 | url = "http://" .. host .. prefix .. "/auth/index.html", |
| 364 | headers = { | 361 | headers = { |
| 365 | authorization = "Basic " .. (socket.mime.b64("luasocket:password")) | 362 | authorization = "Basic " .. (mime.b64("luasocket:password")) |
| 366 | } | 363 | } |
| 367 | } | 364 | } |
| 368 | expect = { | 365 | expect = { |
