From c6868984fba20ed77d2e534ca6e6c1e6ee3ccbf8 Mon Sep 17 00:00:00 2001 From: David Fotel Date: Fri, 8 Jan 2016 04:12:07 +0100 Subject: Rename test/htest.lua -> test/hathawaytest.lua --- test/hathawaytest.lua | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/htest.lua | 160 -------------------------------------------------- 2 files changed, 160 insertions(+), 160 deletions(-) create mode 100755 test/hathawaytest.lua delete mode 100755 test/htest.lua diff --git a/test/hathawaytest.lua b/test/hathawaytest.lua new file mode 100755 index 0000000..efd864f --- /dev/null +++ b/test/hathawaytest.lua @@ -0,0 +1,160 @@ +#!bin/lem +-- +-- This file is part of LEM, a Lua Event Machine. +-- Copyright 2011-2012 Emil Renner Berthing +-- Copyright 2013 Asbjørn Sloth Tønnesen +-- +-- LEM is free software: you can redistribute it and/or modify it +-- under the terms of the GNU Lesser General Public License as +-- published by the Free Software Foundation, either version 3 of +-- the License, or (at your option) any later version. +-- +-- LEM is distributed in the hope that it will be useful, but +-- WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public +-- License along with LEM. If not, see . +-- + +package.path = '?.lua' +package.cpath = '?.so' + +local utils = require 'lem.utils' +local io = require 'lem.io' +local hathaway = require 'lem.hathaway' + +hathaway.debug = print -- must be set before import() +hathaway.import() -- when using single instance API + +GET('/', function(req, res) + print(req.client:getpeer()) + res.status = 302 + res.headers['Location'] = '/dump' +end) + +GET('/hello', function(req, res) + res.headers['Content-Type'] = 'text/plain' + res:add('Hello, World!\n') +end) + +GET('/self', function(req, res) + res.headers['Content-Type'] = 'text/plain' + res.file = arg[0] +end) + +GET('/dump', function(req, res) + local accept = req.headers['accept'] + if accept and accept:match('application/xhtml%+xml') then + res.headers['Content-Type'] = 'application/xhtml+xml' + else + res.headers['Content-Type'] = 'text/html' + end + res:add([[ + + + + Hathaway HTTP dump + + + + +

Request

+ + + + +
Method:%s
Uri:%s
Version:%s
+ +

Headers

+ +]], req.method or '', req.uri or '', req.version) + + for k, v in pairs(req.headers) do + res:add(' \n', k, v) + end + + res:add([[ +
%s%s
+ +

Body

+
+

+
+ +

+
+ +
+

+ + +

+
+ + + +]]) +end) + +local function urldecode(str) + return str:gsub('+', ' '):gsub('%%(%x%x)', function (str) + return string.char(tonumber(str, 16)) + end) +end + +local function parseform(str) + local t = {} + for k, v in str:gmatch('([^&]+)=([^&]*)') do + t[urldecode(k)] = urldecode(v) + end + return t +end + +POST('/form', function(req, res) + res.headers['Content-Type'] = 'text/plain' + local body =req:body() + res:add("You sent:\n%s\n", body) + res:add('{\n') + for k, v in pairs(parseform(body)) do + res:add(" ['%s'] = '%s'\n", k, v) + end + res:add('}\n') +end) + +GET('/close', function(req, res) + res.headers['Content-Type'] = 'text/plain' + res.headers['Connection'] = 'close' + res:add('This connection should close\n') +end) + +POST('/quit', function(req, res) + local body = req:body() + + res.headers['Content-Type'] = 'text/plain' + + if body == 'quit=secret' then + res:add("Bye o/\n") + hathaway.server:close() + else + res:add("You didn't supply the right value...\n") + end +end) + +GETM('^/hello/([^/]+)$', function(req, res, name) + res.headers['Content-Type'] = 'text/plain' + res:add('Hello, %s!\n', name) +end) + +if arg[1] == 'socket' then + local sock = assert(io.unix.listen('socket', 666)) + Hathaway(sock) +else + Hathaway('*', arg[1] or '8080') +end +utils.exit(0) -- otherwise open connections will keep us running + +-- vim: syntax=lua ts=2 sw=2 noet: diff --git a/test/htest.lua b/test/htest.lua deleted file mode 100755 index efd864f..0000000 --- a/test/htest.lua +++ /dev/null @@ -1,160 +0,0 @@ -#!bin/lem --- --- This file is part of LEM, a Lua Event Machine. --- Copyright 2011-2012 Emil Renner Berthing --- Copyright 2013 Asbjørn Sloth Tønnesen --- --- LEM is free software: you can redistribute it and/or modify it --- under the terms of the GNU Lesser General Public License as --- published by the Free Software Foundation, either version 3 of --- the License, or (at your option) any later version. --- --- LEM is distributed in the hope that it will be useful, but --- WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU Lesser General Public License for more details. --- --- You should have received a copy of the GNU Lesser General Public --- License along with LEM. If not, see . --- - -package.path = '?.lua' -package.cpath = '?.so' - -local utils = require 'lem.utils' -local io = require 'lem.io' -local hathaway = require 'lem.hathaway' - -hathaway.debug = print -- must be set before import() -hathaway.import() -- when using single instance API - -GET('/', function(req, res) - print(req.client:getpeer()) - res.status = 302 - res.headers['Location'] = '/dump' -end) - -GET('/hello', function(req, res) - res.headers['Content-Type'] = 'text/plain' - res:add('Hello, World!\n') -end) - -GET('/self', function(req, res) - res.headers['Content-Type'] = 'text/plain' - res.file = arg[0] -end) - -GET('/dump', function(req, res) - local accept = req.headers['accept'] - if accept and accept:match('application/xhtml%+xml') then - res.headers['Content-Type'] = 'application/xhtml+xml' - else - res.headers['Content-Type'] = 'text/html' - end - res:add([[ - - - - Hathaway HTTP dump - - - - -

Request

- - - - -
Method:%s
Uri:%s
Version:%s
- -

Headers

- -]], req.method or '', req.uri or '', req.version) - - for k, v in pairs(req.headers) do - res:add(' \n', k, v) - end - - res:add([[ -
%s%s
- -

Body

-
-

-
- -

-
- -
-

- - -

-
- - - -]]) -end) - -local function urldecode(str) - return str:gsub('+', ' '):gsub('%%(%x%x)', function (str) - return string.char(tonumber(str, 16)) - end) -end - -local function parseform(str) - local t = {} - for k, v in str:gmatch('([^&]+)=([^&]*)') do - t[urldecode(k)] = urldecode(v) - end - return t -end - -POST('/form', function(req, res) - res.headers['Content-Type'] = 'text/plain' - local body =req:body() - res:add("You sent:\n%s\n", body) - res:add('{\n') - for k, v in pairs(parseform(body)) do - res:add(" ['%s'] = '%s'\n", k, v) - end - res:add('}\n') -end) - -GET('/close', function(req, res) - res.headers['Content-Type'] = 'text/plain' - res.headers['Connection'] = 'close' - res:add('This connection should close\n') -end) - -POST('/quit', function(req, res) - local body = req:body() - - res.headers['Content-Type'] = 'text/plain' - - if body == 'quit=secret' then - res:add("Bye o/\n") - hathaway.server:close() - else - res:add("You didn't supply the right value...\n") - end -end) - -GETM('^/hello/([^/]+)$', function(req, res, name) - res.headers['Content-Type'] = 'text/plain' - res:add('Hello, %s!\n', name) -end) - -if arg[1] == 'socket' then - local sock = assert(io.unix.listen('socket', 666)) - Hathaway(sock) -else - Hathaway('*', arg[1] or '8080') -end -utils.exit(0) -- otherwise open connections will keep us running - --- vim: syntax=lua ts=2 sw=2 noet: -- cgit v1.2.1