diff options
author | Emil Renner Berthing <esmil@mailme.dk> | 2013-01-04 00:01:03 +0100 |
---|---|---|
committer | Emil Renner Berthing <esmil@mailme.dk> | 2013-01-04 21:14:27 +0100 |
commit | 62c631fd7d5d5c66694af9266688851ac442508a (patch) | |
tree | 79832de2b0c24b4b9a3c369cde8a99a6b98de6cf /test | |
parent | 2c7077309341aad9f831ae8cf356899a18ee4e3b (diff) | |
download | lem-62c631fd7d5d5c66694af9266688851ac442508a.tar.gz lem-62c631fd7d5d5c66694af9266688851ac442508a.tar.xz lem-62c631fd7d5d5c66694af9266688851ac442508a.zip |
io/tcp: listen() and connect() return host and port
Diffstat (limited to 'test')
-rwxr-xr-x | test/httptest.lua | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/test/httptest.lua b/test/httptest.lua index 5642c0b..9ef07aa 100755 --- a/test/httptest.lua +++ b/test/httptest.lua @@ -24,36 +24,40 @@ local utils = require 'lem.utils' local io = require 'lem.io' local http = require 'lem.http' -local format = string.format -local concat = table.concat +local write, format = io.write, string.format +local function printf(...) + return write(format(...)) +end +local domain, port = 'www.google.com', 'http' +--local domain, port = 'localhost', '8080' local done = false utils.spawn(function() - local conn = assert(io.tcp.connect('www.google.dk', 80)) - --local conn = assert(io.tcp.connect('127.0.0.1', 8080)) + local conn, name, port = assert(io.tcp.connect(domain, port)) - print('\nConnected.') + printf('\nConnected to %s:%u\n', name, port) for i = 1, 2 do - --assert(conn:write('GET / HTTP/1.1\r\nHost: www.google.dk\r\nConnection: close\r\n\r\n')) - assert(conn:write('GET / HTTP/1.1\r\nHost: www.google.dk\r\n\r\n')) + --assert(conn:write('GET / HTTP/1.1\r\nHost: '..domain..'\r\nConnection: close\r\n\r\n')) + assert(conn:write('GET / HTTP/1.1\r\nHost: '..domain..'\r\n\r\n')) local res = assert(conn:read('HTTPResponse')) - print(format('\nHTTP/%s %d %s', res.version, res.status, res.text)) + printf('\nHTTP/%s %d %s\n', res.version, res.status, res.text) for k, v in pairs(res.headers) do - print(format('%s: %s', k, v)) + printf('%s: %s\n', k, v) end - --print(format('\n#body = %d', #assert(conn:read('*a')))) - print(format('\n#body = %d', #assert(res:body()))) + local body = assert(res:body()) + printf('\n#body = %d\n', #body) + --write(body, '\n') end done = true end) -local write, yield = io.write, utils.yield +local yield = utils.yield local sleeper = utils.newsleeper() repeat write('.') |