diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-01-19 00:24:41 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-01-19 00:24:41 +0000 |
| commit | 6ac82d50eecdf9bf55f4234ed3a5449afd7a2992 (patch) | |
| tree | 8cd27e814359d60543428a89b104a8528d0e6bf2 /test | |
| parent | 3ea92711269153916990d6cd7999bf436775e647 (diff) | |
| download | luasocket-6ac82d50eecdf9bf55f4234ed3a5449afd7a2992.tar.gz luasocket-6ac82d50eecdf9bf55f4234ed3a5449afd7a2992.tar.bz2 luasocket-6ac82d50eecdf9bf55f4234ed3a5449afd7a2992.zip | |
Added proxy support to http.lua
Changed callback.lua module, but need more work.
Added local connect support.
Diffstat (limited to 'test')
| -rw-r--r-- | test/httptest.lua | 121 |
1 files changed, 79 insertions, 42 deletions
diff --git a/test/httptest.lua b/test/httptest.lua index 96c9378..3d0db87 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
| @@ -3,6 +3,29 @@ | |||
| 3 | -- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi | 3 | -- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi |
| 4 | -- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" | 4 | -- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" |
| 5 | -- needs "AllowOverride AuthConfig" on /home/c/diego/tec/luasocket/test/auth | 5 | -- needs "AllowOverride AuthConfig" on /home/c/diego/tec/luasocket/test/auth |
| 6 | dofile("noglobals.lua") | ||
| 7 | |||
| 8 | local host, proxyh, proxyp, request, response | ||
| 9 | local ignore, expect, index, prefix, cgiprefix | ||
| 10 | |||
| 11 | local t = socket.time() | ||
| 12 | |||
| 13 | host = host or "diego.princeton.edu" | ||
| 14 | proxyh = proxyh or "localhost" | ||
| 15 | proxyp = proxyp or 3128 | ||
| 16 | prefix = prefix or "/luasocket-test" | ||
| 17 | cgiprefix = cgiprefix or "/luasocket-test-cgi" | ||
| 18 | |||
| 19 | local readfile = function(name) | ||
| 20 | local f = io.open(name, "r") | ||
| 21 | if not f then return nil end | ||
| 22 | local s = f:read("*a") | ||
| 23 | f:close() | ||
| 24 | return s | ||
| 25 | end | ||
| 26 | |||
| 27 | index = readfile("test/index.html") | ||
| 28 | |||
| 6 | local similar = function(s1, s2) | 29 | local similar = function(s1, s2) |
| 7 | return string.lower(string.gsub(s1 or "", "%s", "")) == | 30 | return string.lower(string.gsub(s1 or "", "%s", "")) == |
| 8 | string.lower(string.gsub(s2 or "", "%s", "")) | 31 | string.lower(string.gsub(s2 or "", "%s", "")) |
| @@ -14,14 +37,6 @@ local fail = function(s) | |||
| 14 | os.exit() | 37 | os.exit() |
| 15 | end | 38 | end |
| 16 | 39 | ||
| 17 | local readfile = function(name) | ||
| 18 | local f = io.open(name, "r") | ||
| 19 | if not f then return nil end | ||
| 20 | local s = f:read("*a") | ||
| 21 | f:close() | ||
| 22 | return s | ||
| 23 | end | ||
| 24 | |||
| 25 | local check = function (v, e) | 40 | local check = function (v, e) |
| 26 | if v then print("ok") | 41 | if v then print("ok") |
| 27 | else fail(e) end | 42 | else fail(e) end |
| @@ -48,23 +63,12 @@ local check_request = function(request, expect, ignore) | |||
| 48 | print("ok") | 63 | print("ok") |
| 49 | end | 64 | end |
| 50 | 65 | ||
| 51 | local host, request, response, ignore, expect, index, prefix, cgiprefix | ||
| 52 | |||
| 53 | local t = socket.time() | ||
| 54 | |||
| 55 | host = host or "localhost" | ||
| 56 | prefix = prefix or "/luasocket-test" | ||
| 57 | cgiprefix = cgiprefix or "/luasocket-test-cgi" | ||
| 58 | index = readfile("test/index.html") | ||
| 59 | |||
| 60 | io.write("testing request uri correctness: ") | 66 | io.write("testing request uri correctness: ") |
| 61 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" | 67 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" |
| 62 | local back, h, c, e = socket.http.get("http://" .. host .. forth) | 68 | local back, h, c, e = socket.http.get("http://" .. host .. forth) |
| 63 | if similar(back, forth) then print("ok") | 69 | back = socket.url.parse(back) |
| 64 | else | 70 | if similar(back.query, "this+is+the+query+string") then print("ok") |
| 65 | print(h, c, e) | 71 | else fail() end |
| 66 | fail() | ||
| 67 | end | ||
| 68 | 72 | ||
| 69 | io.write("testing query string correctness: ") | 73 | io.write("testing query string correctness: ") |
| 70 | forth = "this+is+the+query+string" | 74 | forth = "this+is+the+query+string" |
| @@ -86,7 +90,19 @@ ignore = { | |||
| 86 | } | 90 | } |
| 87 | check_request(request, expect, ignore) | 91 | check_request(request, expect, ignore) |
| 88 | 92 | ||
| 89 | socket.http.get("http://" .. host .. prefix .. "/lixo.html") | 93 | io.write("testing redirect loop: ") |
| 94 | request = { | ||
| 95 | url = "http://" .. host .. cgiprefix .. "/redirect-loop" | ||
| 96 | } | ||
| 97 | expect = { | ||
| 98 | code = 302 | ||
| 99 | } | ||
| 100 | ignore = { | ||
| 101 | status = 1, | ||
| 102 | headers = 1, | ||
| 103 | body = 1 | ||
| 104 | } | ||
| 105 | check_request(request, expect, ignore) | ||
| 90 | 106 | ||
| 91 | io.write("testing post method: ") | 107 | io.write("testing post method: ") |
| 92 | -- wanted to test chunked post, but apache doesn't support it... | 108 | -- wanted to test chunked post, but apache doesn't support it... |
| @@ -107,16 +123,35 @@ ignore = { | |||
| 107 | } | 123 | } |
| 108 | check_request(request, expect, ignore) | 124 | check_request(request, expect, ignore) |
| 109 | 125 | ||
| 126 | io.write("testing proxy with post method: ") | ||
| 127 | request = { | ||
| 128 | url = "http://" .. host .. cgiprefix .. "/cat", | ||
| 129 | method = "POST", | ||
| 130 | body = index, | ||
| 131 | headers = { ["content-length"] = string.len(index) }, | ||
| 132 | port = proxyp, | ||
| 133 | host = proxyh | ||
| 134 | } | ||
| 135 | expect = { | ||
| 136 | body = index, | ||
| 137 | code = 200 | ||
| 138 | } | ||
| 139 | ignore = { | ||
| 140 | status = 1, | ||
| 141 | headers = 1 | ||
| 142 | } | ||
| 143 | check_request(request, expect, ignore) | ||
| 144 | |||
| 110 | io.write("testing simple post function: ") | 145 | io.write("testing simple post function: ") |
| 111 | body = socket.http.post("http://" .. host .. cgiprefix .. "/cat", index) | 146 | back = socket.http.post("http://" .. host .. cgiprefix .. "/cat", index) |
| 112 | check(body == index) | 147 | check(back == index) |
| 113 | 148 | ||
| 114 | io.write("testing simple post function with table args: ") | 149 | io.write("testing simple post function with table args: ") |
| 115 | body = socket.http.post { | 150 | back = socket.http.post { |
| 116 | url = "http://" .. host .. cgiprefix .. "/cat", | 151 | url = "http://" .. host .. cgiprefix .. "/cat", |
| 117 | body = index | 152 | body = index |
| 118 | } | 153 | } |
| 119 | check(body == index) | 154 | check(back == index) |
| 120 | 155 | ||
| 121 | io.write("testing http redirection: ") | 156 | io.write("testing http redirection: ") |
| 122 | request = { | 157 | request = { |
| @@ -132,6 +167,22 @@ ignore = { | |||
| 132 | } | 167 | } |
| 133 | check_request(request, expect, ignore) | 168 | check_request(request, expect, ignore) |
| 134 | 169 | ||
| 170 | io.write("testing proxy with redirection: ") | ||
| 171 | request = { | ||
| 172 | url = "http://" .. host .. prefix, | ||
| 173 | host = proxyh, | ||
| 174 | port = proxyp | ||
| 175 | } | ||
| 176 | expect = { | ||
| 177 | body = index, | ||
| 178 | code = 200 | ||
| 179 | } | ||
| 180 | ignore = { | ||
| 181 | status = 1, | ||
| 182 | headers = 1 | ||
| 183 | } | ||
| 184 | check_request(request, expect, ignore) | ||
| 185 | |||
| 135 | 186 | ||
| 136 | io.write("testing automatic auth failure: ") | 187 | io.write("testing automatic auth failure: ") |
| 137 | request = { | 188 | request = { |
| @@ -150,7 +201,7 @@ check_request(request, expect, ignore) | |||
| 150 | io.write("testing http redirection failure: ") | 201 | io.write("testing http redirection failure: ") |
| 151 | request = { | 202 | request = { |
| 152 | url = "http://" .. host .. prefix, | 203 | url = "http://" .. host .. prefix, |
| 153 | stay = 1 | 204 | redirect = false |
| 154 | } | 205 | } |
| 155 | expect = { | 206 | expect = { |
| 156 | code = 301 | 207 | code = 301 |
| @@ -273,20 +324,6 @@ ignore = { | |||
| 273 | } | 324 | } |
| 274 | check_request(request, expect, ignore) | 325 | check_request(request, expect, ignore) |
| 275 | 326 | ||
| 276 | io.write("testing redirect loop: ") | ||
| 277 | request = { | ||
| 278 | url = "http://" .. host .. cgiprefix .. "/redirect-loop" | ||
| 279 | } | ||
| 280 | expect = { | ||
| 281 | code = 302 | ||
| 282 | } | ||
| 283 | ignore = { | ||
| 284 | status = 1, | ||
| 285 | headers = 1, | ||
| 286 | body = 1 | ||
| 287 | } | ||
| 288 | check_request(request, expect, ignore) | ||
| 289 | |||
| 290 | io.write("testing wrong scheme: ") | 327 | io.write("testing wrong scheme: ") |
| 291 | request = { | 328 | request = { |
| 292 | url = "wrong://" .. host .. cgiprefix .. "/cat", | 329 | url = "wrong://" .. host .. cgiprefix .. "/cat", |
