removed 2 locals, fixed http

This commit is contained in:
Thijs Schreijer 2015-03-16 17:06:32 +01:00
parent 9016e91238
commit 8bc5ba604e
3 changed files with 13 additions and 6 deletions

View File

@ -35,8 +35,12 @@ _M.PASSWORD = "anonymous@anonymous.org"
local metat = { __index = {} } local metat = { __index = {} }
function _M.open(params) function _M.open(params)
local c = function() return params:create() end -- wrap create as a method call local tp = socket.try(tp.connect(
local tp = socket.try(tp.connect(params.server, params.port or _M.PORT, _M.TIMEOUT, c)) params.server,
params.port or _M.PORT,
_M.TIMEOUT,
function() return params:create() end -- wrap create as a method call
))
local f = base.setmetatable({ tp = tp }, metat) local f = base.setmetatable({ tp = tp }, metat)
-- make sure everything gets closed in an exception -- make sure everything gets closed in an exception
f.try = socket.newtry(function() f:close() end) f.try = socket.newtry(function() f:close() end)

View File

@ -352,7 +352,7 @@ end
_M.request = socket.protect(function(reqt, body) _M.request = socket.protect(function(reqt, body)
if base.type(reqt) == "string" then if base.type(reqt) == "string" then
reqt = _M.parseRequest(reqt, body) reqt = _M.parseRequest(reqt, body)
local t, code, headers, status = reqt.target, socket.skip(1, trequest(reqt)) local t, code, headers, status = reqt.target, socket.skip(1, _M.request(reqt))
return table.concat(t), code, headers, status return table.concat(t), code, headers, status
else else
reqt.create = reqt.create or socket.tcp reqt.create = reqt.create or socket.tcp

View File

@ -114,9 +114,12 @@ function metat.__index:send(mailt)
end end
function _M.open(mailt) function _M.open(mailt)
local c = function() return mailt:create() end -- wrap to do a method call local tp = socket.try(tp.connect(
local tp = socket.try(tp.connect(mailt.server or _M.SERVER, mailt.port or _M.PORT, mailt.server or _M.SERVER,
_M.TIMEOUT, c)) mailt.port or _M.PORT,
_M.TIMEOUT,
function() return mailt:create() end -- wrap to do a method call
))
local s = base.setmetatable({tp = tp}, metat) local s = base.setmetatable({tp = tp}, metat)
-- make sure tp is closed if we get an exception -- make sure tp is closed if we get an exception
s.try = socket.newtry(function() s.try = socket.newtry(function()