Couple bug fixes.

This commit is contained in:
Diego Nehab 2007-03-12 04:08:40 +00:00
parent 8bf9fb51dd
commit be2e467929
11 changed files with 77 additions and 74 deletions

View file

@ -107,7 +107,7 @@ local metat = { __index = {} }
function open(host, port, create)
-- create socket with user connect function, or with default
local c = socket.try(create or socket.tcp)()
local c = socket.try((create or socket.tcp)())
local h = base.setmetatable({ c = c }, metat)
-- create finalized try
h.try = socket.newtry(function() h:close() end)
@ -228,7 +228,8 @@ local function adjustrequest(reqt)
-- explicit components override url
for i,v in base.pairs(reqt) do nreqt[i] = v end
if nreqt.port == "" then nreqt.port = 80 end
socket.try(nreqt.host, "invalid host '" .. base.tostring(nreqt.host) .. "'")
socket.try(nreqt.host and nreqt.host ~= "",
"invalid host '" .. base.tostring(nreqt.host) .. "'")
-- compute uri if user hasn't overriden
nreqt.uri = reqt.uri or adjusturi(nreqt)
-- ajust host and port if there is a proxy

View file

@ -11,8 +11,9 @@ include ../config
# Modules belonging to socket-core
#
#$(COMPAT)/compat-5.1.o \
SOCKET_OBJS:= \
$(COMPAT)/compat-5.1.o \
luasocket.o \
timeout.o \
buffer.o \
@ -29,10 +30,10 @@ SOCKET_OBJS:= \
#------
# Modules belonging mime-core
#
MIME_OBJS:=\
$(COMPAT)/compat-5.1.o \
mime.o
#$(COMPAT)/compat-5.1.o \
MIME_OBJS:=\
mime.o
#------
# Modules belonging unix (local domain sockets)

View file

@ -122,6 +122,15 @@ function open(server, port, create)
return s
end
-- convert headers to lowercase
local function lower_headers(headers)
local lower = {}
for i,v in base.pairs(headers or lower) do
lower[string.lower(i)] = v
end
return lower
end
---------------------------------------------------------------------------
-- Multipart message source
-----------------------------------------------------------------------------
@ -149,7 +158,7 @@ end
local function send_multipart(mesgt)
-- make sure we have our boundary and send headers
local bd = newboundary()
local headers = mesgt.headers or {}
local headers = lower_headers(mesgt.headers or {})
headers['content-type'] = headers['content-type'] or 'multipart/mixed'
headers['content-type'] = headers['content-type'] ..
'; boundary="' .. bd .. '"'
@ -176,7 +185,7 @@ end
-- yield message body from a source
local function send_source(mesgt)
-- make sure we have a content-type
local headers = mesgt.headers or {}
local headers = lower_headers(mesgt.headers or {})
headers['content-type'] = headers['content-type'] or
'text/plain; charset="iso-8859-1"'
send_headers(headers)
@ -192,7 +201,7 @@ end
-- yield message body from a string
local function send_string(mesgt)
-- make sure we have a content-type
local headers = mesgt.headers or {}
local headers = lower_headers(mesgt.headers or {})
headers['content-type'] = headers['content-type'] or
'text/plain; charset="iso-8859-1"'
send_headers(headers)
@ -209,20 +218,17 @@ end
-- set defaul headers
local function adjust_headers(mesgt)
local lower = {}
for i,v in base.pairs(mesgt.headers or lower) do
lower[string.lower(i)] = v
end
local lower = lower_headers(mesgt.headers)
lower["date"] = lower["date"] or
os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE)
lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
-- this can't be overriden
lower["mime-version"] = "1.0"
mesgt.headers = lower
return lower
end
function message(mesgt)
adjust_headers(mesgt)
mesgt.headers = adjust_headers(mesgt)
-- create and return message source
local co = coroutine.create(function() send_message(mesgt) end)
return function()