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

25
NEW
View File

@ -1,24 +1 @@
What's New
This is just a bug-fix/update release.
* Updated: now using compat-5.1r5;
* Improved: http.request is more robust to malformed
URLs (Adrian Sietsma);
* Improved: the simple http.request interface sends a
"Content-type: application/x-www-form-urlencoded" header
(William Trenker);
* Improved: http.request is robust to evil servers that
send inappropriate 100-continue messages (David Burgess);
* Fixed: http.request was using the old host header during
redirects (Florian Berger);
* Fixed: sample unix.c had fallen through the cracks
during development (Matthew Percival);
* Fixed: error code was not being propagated correctly
in ftp.lua (David Burgess).
Fixed case sensitivity in headers of multipart messages in smtp.message.

25
WISH
View File

@ -1,5 +1,22 @@
... as an l-value
tupples?
... as an l-value to get all results of a function call?
at least ...[i] and #...
extend to full tuples?
__and __or __not metamethods
lua_tostring, lua_tonumber, lua_touseradta etc push values in stack
__tostring,__tonumber, __touserdata metamethods are checked
and expected to push an object of correct type on stack
lua_rawtostring, lua_rawtonumber, lua_rawtouserdata don't
push anything on stack, return data of appropriate type,
skip metamethods and throw error if object not of exact type
package.findfile exported
assert returns all arguments on success
module does not pollute the global namespace
module not polluting the global namespace
coxpcall with a coroutine pool for efficiency (reusing coroutines)
exception mechanism formalized? just like the package system was.
a nice bitlib in the core

33
config
View File

@ -15,22 +15,23 @@ UNIX_SO=unix.$(EXT)
#------
# Lua includes and libraries
#
LUAINC=-I/usr/local/include/lua50
#LUAINC=-I/usr/local/include/lua50
#LUAINC=-I/usr/local/include/lua5.1
LUAINC=-Ilua-5.1.1/src
#------
# Compat-5.1 directory
#
COMPAT=compat-5.1r5
#COMPAT=compat-5.1r5
#------
# Top of your Lua installation
# Relative paths will be inside the src tree
#
INSTALL_TOP_SHARE=/usr/local/share/lua/5.0
INSTALL_TOP_LIB=/usr/local/lib/lua/5.0
#INSTALL_TOP_SHARE=/usr/local/share/lua/5.1
#INSTALL_TOP_LIB=/usr/local/lib/lua/5.1
#INSTALL_TOP_SHARE=/usr/local/share/lua/5.0
#INSTALL_TOP_LIB=/usr/local/lib/lua/5.0
INSTALL_TOP_SHARE=/usr/local/share/lua/5.1
INSTALL_TOP_LIB=/usr/local/lib/lua/5.1
INSTALL_DATA=cp
INSTALL_EXEC=cp
@ -39,20 +40,20 @@ INSTALL_EXEC=cp
# Compiler and linker settings
# for Mac OS X
#
#CC=gcc
#DEF=-DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN
#CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common
#LDFLAGS=-bundle -undefined dynamic_lookup
#LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc
CC=gcc
DEF=-DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN
CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common
LDFLAGS=-bundle -undefined dynamic_lookup
LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc
#------
# Compiler and linker settings
# for Linux
CC=gcc
DEF=-DLUASOCKET_DEBUG
CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fpic
LDFLAGS=-O -shared -fpic
LD=gcc
#CC=gcc
#DEF=-DLUASOCKET_DEBUG
#CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fpic
#LDFLAGS=-O -shared -fpic
#LD=gcc
#------
# End of makefile configuration

View File

@ -65,21 +65,23 @@ end
-- kind of copied from luasocket's manual callback examples
function stats(size)
local start = socket.gettime()
local last = start
local got = 0
return function(chunk)
-- elapsed time since start
local delta = socket.gettime() - start
local current = socket.gettime()
if chunk then
-- total bytes received
got = got + string.len(chunk)
-- not enough time for estimate
if delta > 0.1 then
io.stderr:write("\r", gauge(got, delta, size))
if current - last > 1 then
io.stderr:write("\r", gauge(got, current - start, size))
io.stderr:flush()
last = current
end
else
-- close up
io.stderr:write("\r", gauge(got, delta), "\n")
io.stderr:write("\r", gauge(got, current - start), "\n")
end
return chunk
end

View File

@ -25,7 +25,6 @@ TO_SOCKET_SHARE:= \
smtp.lua
TO_TOP_SHARE:= \
$(COMPAT)/compat-5.1.lua \
ltn12.lua \
socket.lua \
mime.lua

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()

View File

@ -119,9 +119,8 @@ check_request(request, expect, ignore)
------------------------------------------------------------------------
io.write("testing invalid url: ")
local c, e = socket.connect("", 80)
local r, re = http.request{url = host .. prefix}
assert(r == nil and e == re)
local r, e = http.request{url = host .. prefix}
assert(r == nil and e == "invalid host ''")
r, re = http.request(host .. prefix)
assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) ..
" vs " .. tostring(e))

View File

@ -101,7 +101,7 @@ control:setoption("tcp-nodelay", true)
------------------------------------------------------------------------
function test_methods(sock, methods)
for _, v in methods do
for _, v in pairs(methods) do
if type(sock[v]) ~= "function" then
fail(sock.class .. " method '" .. v .. "' not registered")
end

View File

@ -12,7 +12,7 @@ source = smtp.message {
headers = { ['content-type'] = 'multipart/alternative' },
body = {
[1] = {
headers = { ['content-type'] = 'text/html' },
headers = { ['Content-type'] = 'text/html' },
body = "<html> <body> Hi, <b>there</b>...</body> </html>"
},
[2] = {
@ -60,7 +60,7 @@ source = smtp.message{
-- chunks are loaded into memory and translation happens on the fly.
[2] = {
headers = {
["content-type"] = 'image/png; name="luasocket.png"',
["ConTenT-tYpE"] = 'image/png; name="luasocket.png"',
["content-disposition"] = 'attachment; filename="luasocket.png"',
["content-description"] = 'a beautiful image',
["content-transfer-encoding"] = "BASE64"
@ -83,10 +83,10 @@ r, e = smtp.send{
"<diego@princeton.edu>" },
from = "<diego@princeton.edu>",
source = ltn12.source.chain(source, filter),
server = "mail.cs.princeton.edu",
--server = "localhost",
--port = 2525
port = 25
--server = "mail.cs.princeton.edu",
--port = 25
server = "localhost",
port = 2525
}
print(r, e)