diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-28 22:41:26 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-28 22:41:26 +0000 |
| commit | 4755ad727e36f2c3ad644718a2d477fffa9b1d23 (patch) | |
| tree | cc24c7c87945cefd90521a509bc7526043895391 | |
| parent | 335cdbf334dde609c32cc46ad9536980066504f6 (diff) | |
| download | luasocket-4755ad727e36f2c3ad644718a2d477fffa9b1d23.tar.gz luasocket-4755ad727e36f2c3ad644718a2d477fffa9b1d23.tar.bz2 luasocket-4755ad727e36f2c3ad644718a2d477fffa9b1d23.zip | |
Compiled in WinXP
| -rw-r--r-- | test/httptest.lua | 42 |
1 files changed, 21 insertions, 21 deletions
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 | |||
| 49 | 49 | ||
| 50 | local t = socket._time() | 50 | local t = socket._time() |
| 51 | 51 | ||
| 52 | HOST = HOST or "localhost" | 52 | host = host or "localhost" |
| 53 | prefix = prefix or "/luasocket" | 53 | prefix = prefix or "/luasocket" |
| 54 | cgiprefix = cgiprefix or "/luasocket/cgi" | 54 | cgiprefix = cgiprefix or "/luasocket/cgi" |
| 55 | index = readfile("test/index.html") | 55 | index = readfile("test/index.html") |
| 56 | 56 | ||
| 57 | io.write("testing request uri correctness: ") | 57 | io.write("testing request uri correctness: ") |
| 58 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" | 58 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" |
| 59 | local back = socket.http.get("http://" .. HOST .. forth) | 59 | local back = socket.http.get("http://" .. host .. forth) |
| 60 | if similar(back, forth) then print("ok") | 60 | if similar(back, forth) then print("ok") |
| 61 | else fail("failed!") end | 61 | else fail("failed!") end |
| 62 | 62 | ||
| 63 | io.write("testing query string correctness: ") | 63 | io.write("testing query string correctness: ") |
| 64 | forth = "this+is+the+query+string" | 64 | forth = "this+is+the+query+string" |
| 65 | back = socket.http.get("http://" .. HOST .. cgiprefix .. "/query-string?" .. forth) | 65 | back = socket.http.get("http://" .. host .. cgiprefix .. "/query-string?" .. forth) |
| 66 | if similar(back, forth) then print("ok") | 66 | if similar(back, forth) then print("ok") |
| 67 | else fail("failed!") end | 67 | else fail("failed!") end |
| 68 | 68 | ||
| 69 | io.write("testing document retrieval: ") | 69 | io.write("testing document retrieval: ") |
| 70 | request = { | 70 | request = { |
| 71 | url = "http://" .. HOST .. prefix .. "/index.html" | 71 | url = "http://" .. host .. prefix .. "/index.html" |
| 72 | } | 72 | } |
| 73 | expect = { | 73 | expect = { |
| 74 | body = index, | 74 | body = index, |
| @@ -82,7 +82,7 @@ check_request(request, expect, ignore) | |||
| 82 | 82 | ||
| 83 | io.write("testing http redirection: ") | 83 | io.write("testing http redirection: ") |
| 84 | request = { | 84 | request = { |
| 85 | url = "http://" .. HOST .. prefix | 85 | url = "http://" .. host .. prefix |
| 86 | } | 86 | } |
| 87 | expect = { | 87 | expect = { |
| 88 | body = index, | 88 | body = index, |
| @@ -97,7 +97,7 @@ check_request(request, expect, ignore) | |||
| 97 | 97 | ||
| 98 | io.write("testing automatic auth failure: ") | 98 | io.write("testing automatic auth failure: ") |
| 99 | request = { | 99 | request = { |
| 100 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html" | 100 | url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html" |
| 101 | } | 101 | } |
| 102 | expect = { | 102 | expect = { |
| 103 | code = 401 | 103 | code = 401 |
| @@ -111,7 +111,7 @@ check_request(request, expect, ignore) | |||
| 111 | 111 | ||
| 112 | io.write("testing http redirection failure: ") | 112 | io.write("testing http redirection failure: ") |
| 113 | request = { | 113 | request = { |
| 114 | url = "http://" .. HOST .. prefix, | 114 | url = "http://" .. host .. prefix, |
| 115 | stay = 1 | 115 | stay = 1 |
| 116 | } | 116 | } |
| 117 | expect = { | 117 | expect = { |
| @@ -137,7 +137,7 @@ check_request(request, expect, ignore) | |||
| 137 | 137 | ||
| 138 | io.write("testing invalid url: ") | 138 | io.write("testing invalid url: ") |
| 139 | request = { | 139 | request = { |
| 140 | url = HOST .. prefix | 140 | url = host .. prefix |
| 141 | } | 141 | } |
| 142 | local c, e = socket.connect("", 80) | 142 | local c, e = socket.connect("", 80) |
| 143 | expect = { | 143 | expect = { |
| @@ -148,7 +148,7 @@ check_request(request, expect, ignore) | |||
| 148 | 148 | ||
| 149 | io.write("testing document not found: ") | 149 | io.write("testing document not found: ") |
| 150 | request = { | 150 | request = { |
| 151 | url = "http://" .. HOST .. "/wrongdocument.html" | 151 | url = "http://" .. host .. "/wrongdocument.html" |
| 152 | } | 152 | } |
| 153 | expect = { | 153 | expect = { |
| 154 | code = 404 | 154 | code = 404 |
| @@ -162,7 +162,7 @@ check_request(request, expect, ignore) | |||
| 162 | 162 | ||
| 163 | io.write("testing auth failure: ") | 163 | io.write("testing auth failure: ") |
| 164 | request = { | 164 | request = { |
| 165 | url = "http://" .. HOST .. prefix .. "/auth/index.html" | 165 | url = "http://" .. host .. prefix .. "/auth/index.html" |
| 166 | } | 166 | } |
| 167 | expect = { | 167 | expect = { |
| 168 | code = 401 | 168 | code = 401 |
| @@ -176,7 +176,7 @@ check_request(request, expect, ignore) | |||
| 176 | 176 | ||
| 177 | io.write("testing manual basic auth: ") | 177 | io.write("testing manual basic auth: ") |
| 178 | request = { | 178 | request = { |
| 179 | url = "http://" .. HOST .. prefix .. "/auth/index.html", | 179 | url = "http://" .. host .. prefix .. "/auth/index.html", |
| 180 | headers = { | 180 | headers = { |
| 181 | authorization = "Basic " .. socket.code.base64("luasocket:password") | 181 | authorization = "Basic " .. socket.code.base64("luasocket:password") |
| 182 | } | 182 | } |
| @@ -193,7 +193,7 @@ check_request(request, expect, ignore) | |||
| 193 | 193 | ||
| 194 | io.write("testing automatic basic auth: ") | 194 | io.write("testing automatic basic auth: ") |
| 195 | request = { | 195 | request = { |
| 196 | url = "http://luasocket:password@" .. HOST .. prefix .. "/auth/index.html" | 196 | url = "http://luasocket:password@" .. host .. prefix .. "/auth/index.html" |
| 197 | } | 197 | } |
| 198 | expect = { | 198 | expect = { |
| 199 | code = 200, | 199 | code = 200, |
| @@ -207,7 +207,7 @@ check_request(request, expect, ignore) | |||
| 207 | 207 | ||
| 208 | io.write("testing auth info overriding: ") | 208 | io.write("testing auth info overriding: ") |
| 209 | request = { | 209 | request = { |
| 210 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", | 210 | url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html", |
| 211 | user = "luasocket", | 211 | user = "luasocket", |
| 212 | password = "password" | 212 | password = "password" |
| 213 | } | 213 | } |
| @@ -223,7 +223,7 @@ check_request(request, expect, ignore) | |||
| 223 | 223 | ||
| 224 | io.write("testing cgi output retrieval (probably chunked...): ") | 224 | io.write("testing cgi output retrieval (probably chunked...): ") |
| 225 | request = { | 225 | request = { |
| 226 | url = "http://" .. HOST .. cgiprefix .. "/cat-index-html" | 226 | url = "http://" .. host .. cgiprefix .. "/cat-index-html" |
| 227 | } | 227 | } |
| 228 | expect = { | 228 | expect = { |
| 229 | body = index, | 229 | body = index, |
| @@ -237,7 +237,7 @@ check_request(request, expect, ignore) | |||
| 237 | 237 | ||
| 238 | io.write("testing redirect loop: ") | 238 | io.write("testing redirect loop: ") |
| 239 | request = { | 239 | request = { |
| 240 | url = "http://" .. HOST .. cgiprefix .. "/redirect-loop" | 240 | url = "http://" .. host .. cgiprefix .. "/redirect-loop" |
| 241 | } | 241 | } |
| 242 | expect = { | 242 | expect = { |
| 243 | code = 302 | 243 | code = 302 |
| @@ -251,7 +251,7 @@ check_request(request, expect, ignore) | |||
| 251 | 251 | ||
| 252 | io.write("testing post method: ") | 252 | io.write("testing post method: ") |
| 253 | request = { | 253 | request = { |
| 254 | url = "http://" .. HOST .. cgiprefix .. "/cat", | 254 | url = "http://" .. host .. cgiprefix .. "/cat", |
| 255 | method = "POST", | 255 | method = "POST", |
| 256 | body = index | 256 | body = index |
| 257 | } | 257 | } |
| @@ -267,7 +267,7 @@ check_request(request, expect, ignore) | |||
| 267 | 267 | ||
| 268 | io.write("testing wrong scheme: ") | 268 | io.write("testing wrong scheme: ") |
| 269 | request = { | 269 | request = { |
| 270 | url = "wrong://" .. HOST .. cgiprefix .. "/cat", | 270 | url = "wrong://" .. host .. cgiprefix .. "/cat", |
| 271 | method = "GET" | 271 | method = "GET" |
| 272 | } | 272 | } |
| 273 | expect = { | 273 | expect = { |
| @@ -279,24 +279,24 @@ check_request(request, expect, ignore) | |||
| 279 | 279 | ||
| 280 | local body | 280 | local body |
| 281 | io.write("testing simple get function: ") | 281 | io.write("testing simple get function: ") |
| 282 | body = socket.http.get("http://" .. HOST .. prefix .. "/index.html") | 282 | body = socket.http.get("http://" .. host .. prefix .. "/index.html") |
| 283 | check(body == index) | 283 | check(body == index) |
| 284 | 284 | ||
| 285 | io.write("testing simple get function with table args: ") | 285 | io.write("testing simple get function with table args: ") |
| 286 | body = socket.http.get { | 286 | body = socket.http.get { |
| 287 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", | 287 | url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html", |
| 288 | user = "luasocket", | 288 | user = "luasocket", |
| 289 | password = "password" | 289 | password = "password" |
| 290 | } | 290 | } |
| 291 | check(body == index) | 291 | check(body == index) |
| 292 | 292 | ||
| 293 | io.write("testing simple post function: ") | 293 | io.write("testing simple post function: ") |
| 294 | body = socket.http.post("http://" .. HOST .. cgiprefix .. "/cat", index) | 294 | body = socket.http.post("http://" .. host .. cgiprefix .. "/cat", index) |
| 295 | check(body == index) | 295 | check(body == index) |
| 296 | 296 | ||
| 297 | io.write("testing simple post function with table args: ") | 297 | io.write("testing simple post function with table args: ") |
| 298 | body = socket.http.post { | 298 | body = socket.http.post { |
| 299 | url = "http://" .. HOST .. cgiprefix .. "/cat", | 299 | url = "http://" .. host .. cgiprefix .. "/cat", |
| 300 | body = index | 300 | body = index |
| 301 | } | 301 | } |
| 302 | check(body == index) | 302 | check(body == index) |
