diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2007-03-12 04:08:40 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2007-03-12 04:08:40 +0000 |
| commit | be2e467929be9f27fbe92fe7b94783635c920c06 (patch) | |
| tree | 94054e38f33178d805a6144d3bd9cb76da4a4c76 | |
| parent | 8bf9fb51dd09fb066483247fccbfc979acc84071 (diff) | |
| download | luasocket-be2e467929be9f27fbe92fe7b94783635c920c06.tar.gz luasocket-be2e467929be9f27fbe92fe7b94783635c920c06.tar.bz2 luasocket-be2e467929be9f27fbe92fe7b94783635c920c06.zip | |
Couple bug fixes.
| -rw-r--r-- | NEW | 25 | ||||
| -rw-r--r-- | WISH | 25 | ||||
| -rw-r--r-- | config | 33 | ||||
| -rw-r--r-- | etc/get.lua | 10 | ||||
| -rw-r--r-- | makefile | 1 | ||||
| -rw-r--r-- | src/http.lua | 5 | ||||
| -rw-r--r-- | src/makefile | 7 | ||||
| -rw-r--r-- | src/smtp.lua | 24 | ||||
| -rw-r--r-- | test/httptest.lua | 5 | ||||
| -rw-r--r-- | test/testclnt.lua | 2 | ||||
| -rw-r--r-- | test/testmesg.lua | 12 |
11 files changed, 76 insertions, 73 deletions
| @@ -1,24 +1 @@ | |||
| 1 | What's New | Fixed case sensitivity in headers of multipart messages in smtp.message. | |
| 2 | |||
| 3 | This is just a bug-fix/update release. | ||
| 4 | |||
| 5 | * Updated: now using compat-5.1r5; | ||
| 6 | |||
| 7 | * Improved: http.request is more robust to malformed | ||
| 8 | URLs (Adrian Sietsma); | ||
| 9 | |||
| 10 | * Improved: the simple http.request interface sends a | ||
| 11 | "Content-type: application/x-www-form-urlencoded" header | ||
| 12 | (William Trenker); | ||
| 13 | |||
| 14 | * Improved: http.request is robust to evil servers that | ||
| 15 | send inappropriate 100-continue messages (David Burgess); | ||
| 16 | |||
| 17 | * Fixed: http.request was using the old host header during | ||
| 18 | redirects (Florian Berger); | ||
| 19 | |||
| 20 | * Fixed: sample unix.c had fallen through the cracks | ||
| 21 | during development (Matthew Percival); | ||
| 22 | |||
| 23 | * Fixed: error code was not being propagated correctly | ||
| 24 | in ftp.lua (David Burgess). | ||
| @@ -1,5 +1,22 @@ | |||
| 1 | ... as an l-value | 1 | ... as an l-value to get all results of a function call? |
| 2 | tupples? | 2 | at least ...[i] and #... |
| 3 | extend to full tuples? | ||
| 4 | |||
| 5 | __and __or __not metamethods | ||
| 6 | |||
| 7 | lua_tostring, lua_tonumber, lua_touseradta etc push values in stack | ||
| 8 | __tostring,__tonumber, __touserdata metamethods are checked | ||
| 9 | and expected to push an object of correct type on stack | ||
| 10 | |||
| 11 | lua_rawtostring, lua_rawtonumber, lua_rawtouserdata don't | ||
| 12 | push anything on stack, return data of appropriate type, | ||
| 13 | skip metamethods and throw error if object not of exact type | ||
| 14 | |||
| 3 | package.findfile exported | 15 | package.findfile exported |
| 4 | assert returns all arguments on success | 16 | module not polluting the global namespace |
| 5 | module does not pollute the global namespace | 17 | |
| 18 | coxpcall with a coroutine pool for efficiency (reusing coroutines) | ||
| 19 | |||
| 20 | exception mechanism formalized? just like the package system was. | ||
| 21 | |||
| 22 | a nice bitlib in the core | ||
| @@ -15,22 +15,23 @@ UNIX_SO=unix.$(EXT) | |||
| 15 | #------ | 15 | #------ |
| 16 | # Lua includes and libraries | 16 | # Lua includes and libraries |
| 17 | # | 17 | # |
| 18 | LUAINC=-I/usr/local/include/lua50 | 18 | #LUAINC=-I/usr/local/include/lua50 |
| 19 | #LUAINC=-I/usr/local/include/lua5.1 | 19 | #LUAINC=-I/usr/local/include/lua5.1 |
| 20 | LUAINC=-Ilua-5.1.1/src | ||
| 20 | 21 | ||
| 21 | #------ | 22 | #------ |
| 22 | # Compat-5.1 directory | 23 | # Compat-5.1 directory |
| 23 | # | 24 | # |
| 24 | COMPAT=compat-5.1r5 | 25 | #COMPAT=compat-5.1r5 |
| 25 | 26 | ||
| 26 | #------ | 27 | #------ |
| 27 | # Top of your Lua installation | 28 | # Top of your Lua installation |
| 28 | # Relative paths will be inside the src tree | 29 | # Relative paths will be inside the src tree |
| 29 | # | 30 | # |
| 30 | INSTALL_TOP_SHARE=/usr/local/share/lua/5.0 | 31 | #INSTALL_TOP_SHARE=/usr/local/share/lua/5.0 |
| 31 | INSTALL_TOP_LIB=/usr/local/lib/lua/5.0 | 32 | #INSTALL_TOP_LIB=/usr/local/lib/lua/5.0 |
| 32 | #INSTALL_TOP_SHARE=/usr/local/share/lua/5.1 | 33 | INSTALL_TOP_SHARE=/usr/local/share/lua/5.1 |
| 33 | #INSTALL_TOP_LIB=/usr/local/lib/lua/5.1 | 34 | INSTALL_TOP_LIB=/usr/local/lib/lua/5.1 |
| 34 | 35 | ||
| 35 | INSTALL_DATA=cp | 36 | INSTALL_DATA=cp |
| 36 | INSTALL_EXEC=cp | 37 | INSTALL_EXEC=cp |
| @@ -39,20 +40,20 @@ INSTALL_EXEC=cp | |||
| 39 | # Compiler and linker settings | 40 | # Compiler and linker settings |
| 40 | # for Mac OS X | 41 | # for Mac OS X |
| 41 | # | 42 | # |
| 42 | #CC=gcc | 43 | CC=gcc |
| 43 | #DEF=-DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN | 44 | DEF=-DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN |
| 44 | #CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common | 45 | CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common |
| 45 | #LDFLAGS=-bundle -undefined dynamic_lookup | 46 | LDFLAGS=-bundle -undefined dynamic_lookup |
| 46 | #LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc | 47 | LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc |
| 47 | 48 | ||
| 48 | #------ | 49 | #------ |
| 49 | # Compiler and linker settings | 50 | # Compiler and linker settings |
| 50 | # for Linux | 51 | # for Linux |
| 51 | CC=gcc | 52 | #CC=gcc |
| 52 | DEF=-DLUASOCKET_DEBUG | 53 | #DEF=-DLUASOCKET_DEBUG |
| 53 | CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fpic | 54 | #CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fpic |
| 54 | LDFLAGS=-O -shared -fpic | 55 | #LDFLAGS=-O -shared -fpic |
| 55 | LD=gcc | 56 | #LD=gcc |
| 56 | 57 | ||
| 57 | #------ | 58 | #------ |
| 58 | # End of makefile configuration | 59 | # End of makefile configuration |
diff --git a/etc/get.lua b/etc/get.lua index ebf3e75..09f639d 100644 --- a/etc/get.lua +++ b/etc/get.lua | |||
| @@ -65,21 +65,23 @@ end | |||
| 65 | -- kind of copied from luasocket's manual callback examples | 65 | -- kind of copied from luasocket's manual callback examples |
| 66 | function stats(size) | 66 | function stats(size) |
| 67 | local start = socket.gettime() | 67 | local start = socket.gettime() |
| 68 | local last = start | ||
| 68 | local got = 0 | 69 | local got = 0 |
| 69 | return function(chunk) | 70 | return function(chunk) |
| 70 | -- elapsed time since start | 71 | -- elapsed time since start |
| 71 | local delta = socket.gettime() - start | 72 | local current = socket.gettime() |
| 72 | if chunk then | 73 | if chunk then |
| 73 | -- total bytes received | 74 | -- total bytes received |
| 74 | got = got + string.len(chunk) | 75 | got = got + string.len(chunk) |
| 75 | -- not enough time for estimate | 76 | -- not enough time for estimate |
| 76 | if delta > 0.1 then | 77 | if current - last > 1 then |
| 77 | io.stderr:write("\r", gauge(got, delta, size)) | 78 | io.stderr:write("\r", gauge(got, current - start, size)) |
| 78 | io.stderr:flush() | 79 | io.stderr:flush() |
| 80 | last = current | ||
| 79 | end | 81 | end |
| 80 | else | 82 | else |
| 81 | -- close up | 83 | -- close up |
| 82 | io.stderr:write("\r", gauge(got, delta), "\n") | 84 | io.stderr:write("\r", gauge(got, current - start), "\n") |
| 83 | end | 85 | end |
| 84 | return chunk | 86 | return chunk |
| 85 | end | 87 | end |
| @@ -25,7 +25,6 @@ TO_SOCKET_SHARE:= \ | |||
| 25 | smtp.lua | 25 | smtp.lua |
| 26 | 26 | ||
| 27 | TO_TOP_SHARE:= \ | 27 | TO_TOP_SHARE:= \ |
| 28 | $(COMPAT)/compat-5.1.lua \ | ||
| 29 | ltn12.lua \ | 28 | ltn12.lua \ |
| 30 | socket.lua \ | 29 | socket.lua \ |
| 31 | mime.lua | 30 | mime.lua |
diff --git a/src/http.lua b/src/http.lua index 558f347..9d739a4 100644 --- a/src/http.lua +++ b/src/http.lua | |||
| @@ -107,7 +107,7 @@ local metat = { __index = {} } | |||
| 107 | 107 | ||
| 108 | function open(host, port, create) | 108 | function open(host, port, create) |
| 109 | -- create socket with user connect function, or with default | 109 | -- create socket with user connect function, or with default |
| 110 | local c = socket.try(create or socket.tcp)() | 110 | local c = socket.try((create or socket.tcp)()) |
| 111 | local h = base.setmetatable({ c = c }, metat) | 111 | local h = base.setmetatable({ c = c }, metat) |
| 112 | -- create finalized try | 112 | -- create finalized try |
| 113 | h.try = socket.newtry(function() h:close() end) | 113 | h.try = socket.newtry(function() h:close() end) |
| @@ -228,7 +228,8 @@ local function adjustrequest(reqt) | |||
| 228 | -- explicit components override url | 228 | -- explicit components override url |
| 229 | for i,v in base.pairs(reqt) do nreqt[i] = v end | 229 | for i,v in base.pairs(reqt) do nreqt[i] = v end |
| 230 | if nreqt.port == "" then nreqt.port = 80 end | 230 | if nreqt.port == "" then nreqt.port = 80 end |
| 231 | socket.try(nreqt.host, "invalid host '" .. base.tostring(nreqt.host) .. "'") | 231 | socket.try(nreqt.host and nreqt.host ~= "", |
| 232 | "invalid host '" .. base.tostring(nreqt.host) .. "'") | ||
| 232 | -- compute uri if user hasn't overriden | 233 | -- compute uri if user hasn't overriden |
| 233 | nreqt.uri = reqt.uri or adjusturi(nreqt) | 234 | nreqt.uri = reqt.uri or adjusturi(nreqt) |
| 234 | -- ajust host and port if there is a proxy | 235 | -- ajust host and port if there is a proxy |
diff --git a/src/makefile b/src/makefile index a21a346..b614f77 100644 --- a/src/makefile +++ b/src/makefile | |||
| @@ -11,8 +11,9 @@ include ../config | |||
| 11 | # Modules belonging to socket-core | 11 | # Modules belonging to socket-core |
| 12 | # | 12 | # |
| 13 | 13 | ||
| 14 | #$(COMPAT)/compat-5.1.o \ | ||
| 15 | |||
| 14 | SOCKET_OBJS:= \ | 16 | SOCKET_OBJS:= \ |
| 15 | $(COMPAT)/compat-5.1.o \ | ||
| 16 | luasocket.o \ | 17 | luasocket.o \ |
| 17 | timeout.o \ | 18 | timeout.o \ |
| 18 | buffer.o \ | 19 | buffer.o \ |
| @@ -29,11 +30,11 @@ SOCKET_OBJS:= \ | |||
| 29 | #------ | 30 | #------ |
| 30 | # Modules belonging mime-core | 31 | # Modules belonging mime-core |
| 31 | # | 32 | # |
| 33 | #$(COMPAT)/compat-5.1.o \ | ||
| 34 | |||
| 32 | MIME_OBJS:=\ | 35 | MIME_OBJS:=\ |
| 33 | $(COMPAT)/compat-5.1.o \ | ||
| 34 | mime.o | 36 | mime.o |
| 35 | 37 | ||
| 36 | |||
| 37 | #------ | 38 | #------ |
| 38 | # Modules belonging unix (local domain sockets) | 39 | # Modules belonging unix (local domain sockets) |
| 39 | # | 40 | # |
diff --git a/src/smtp.lua b/src/smtp.lua index 2257a69..9a204d8 100644 --- a/src/smtp.lua +++ b/src/smtp.lua | |||
| @@ -122,6 +122,15 @@ function open(server, port, create) | |||
| 122 | return s | 122 | return s |
| 123 | end | 123 | end |
| 124 | 124 | ||
| 125 | -- convert headers to lowercase | ||
| 126 | local function lower_headers(headers) | ||
| 127 | local lower = {} | ||
| 128 | for i,v in base.pairs(headers or lower) do | ||
| 129 | lower[string.lower(i)] = v | ||
| 130 | end | ||
| 131 | return lower | ||
| 132 | end | ||
| 133 | |||
| 125 | --------------------------------------------------------------------------- | 134 | --------------------------------------------------------------------------- |
| 126 | -- Multipart message source | 135 | -- Multipart message source |
| 127 | ----------------------------------------------------------------------------- | 136 | ----------------------------------------------------------------------------- |
| @@ -149,7 +158,7 @@ end | |||
| 149 | local function send_multipart(mesgt) | 158 | local function send_multipart(mesgt) |
| 150 | -- make sure we have our boundary and send headers | 159 | -- make sure we have our boundary and send headers |
| 151 | local bd = newboundary() | 160 | local bd = newboundary() |
| 152 | local headers = mesgt.headers or {} | 161 | local headers = lower_headers(mesgt.headers or {}) |
| 153 | headers['content-type'] = headers['content-type'] or 'multipart/mixed' | 162 | headers['content-type'] = headers['content-type'] or 'multipart/mixed' |
| 154 | headers['content-type'] = headers['content-type'] .. | 163 | headers['content-type'] = headers['content-type'] .. |
| 155 | '; boundary="' .. bd .. '"' | 164 | '; boundary="' .. bd .. '"' |
| @@ -176,7 +185,7 @@ end | |||
| 176 | -- yield message body from a source | 185 | -- yield message body from a source |
| 177 | local function send_source(mesgt) | 186 | local function send_source(mesgt) |
| 178 | -- make sure we have a content-type | 187 | -- make sure we have a content-type |
| 179 | local headers = mesgt.headers or {} | 188 | local headers = lower_headers(mesgt.headers or {}) |
| 180 | headers['content-type'] = headers['content-type'] or | 189 | headers['content-type'] = headers['content-type'] or |
| 181 | 'text/plain; charset="iso-8859-1"' | 190 | 'text/plain; charset="iso-8859-1"' |
| 182 | send_headers(headers) | 191 | send_headers(headers) |
| @@ -192,7 +201,7 @@ end | |||
| 192 | -- yield message body from a string | 201 | -- yield message body from a string |
| 193 | local function send_string(mesgt) | 202 | local function send_string(mesgt) |
| 194 | -- make sure we have a content-type | 203 | -- make sure we have a content-type |
| 195 | local headers = mesgt.headers or {} | 204 | local headers = lower_headers(mesgt.headers or {}) |
| 196 | headers['content-type'] = headers['content-type'] or | 205 | headers['content-type'] = headers['content-type'] or |
| 197 | 'text/plain; charset="iso-8859-1"' | 206 | 'text/plain; charset="iso-8859-1"' |
| 198 | send_headers(headers) | 207 | send_headers(headers) |
| @@ -209,20 +218,17 @@ end | |||
| 209 | 218 | ||
| 210 | -- set defaul headers | 219 | -- set defaul headers |
| 211 | local function adjust_headers(mesgt) | 220 | local function adjust_headers(mesgt) |
| 212 | local lower = {} | 221 | local lower = lower_headers(mesgt.headers) |
| 213 | for i,v in base.pairs(mesgt.headers or lower) do | ||
| 214 | lower[string.lower(i)] = v | ||
| 215 | end | ||
| 216 | lower["date"] = lower["date"] or | 222 | lower["date"] = lower["date"] or |
| 217 | os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE) | 223 | os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE) |
| 218 | lower["x-mailer"] = lower["x-mailer"] or socket._VERSION | 224 | lower["x-mailer"] = lower["x-mailer"] or socket._VERSION |
| 219 | -- this can't be overriden | 225 | -- this can't be overriden |
| 220 | lower["mime-version"] = "1.0" | 226 | lower["mime-version"] = "1.0" |
| 221 | mesgt.headers = lower | 227 | return lower |
| 222 | end | 228 | end |
| 223 | 229 | ||
| 224 | function message(mesgt) | 230 | function message(mesgt) |
| 225 | adjust_headers(mesgt) | 231 | mesgt.headers = adjust_headers(mesgt) |
| 226 | -- create and return message source | 232 | -- create and return message source |
| 227 | local co = coroutine.create(function() send_message(mesgt) end) | 233 | local co = coroutine.create(function() send_message(mesgt) end) |
| 228 | return function() | 234 | return function() |
diff --git a/test/httptest.lua b/test/httptest.lua index ac60787..dd53ec3 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
| @@ -119,9 +119,8 @@ check_request(request, expect, ignore) | |||
| 119 | 119 | ||
| 120 | ------------------------------------------------------------------------ | 120 | ------------------------------------------------------------------------ |
| 121 | io.write("testing invalid url: ") | 121 | io.write("testing invalid url: ") |
| 122 | local c, e = socket.connect("", 80) | 122 | local r, e = http.request{url = host .. prefix} |
| 123 | local r, re = http.request{url = host .. prefix} | 123 | assert(r == nil and e == "invalid host ''") |
| 124 | assert(r == nil and e == re) | ||
| 125 | r, re = http.request(host .. prefix) | 124 | r, re = http.request(host .. prefix) |
| 126 | assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) .. | 125 | assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) .. |
| 127 | " vs " .. tostring(e)) | 126 | " vs " .. tostring(e)) |
diff --git a/test/testclnt.lua b/test/testclnt.lua index cf71c9f..304cfd3 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
| @@ -101,7 +101,7 @@ control:setoption("tcp-nodelay", true) | |||
| 101 | 101 | ||
| 102 | ------------------------------------------------------------------------ | 102 | ------------------------------------------------------------------------ |
| 103 | function test_methods(sock, methods) | 103 | function test_methods(sock, methods) |
| 104 | for _, v in methods do | 104 | for _, v in pairs(methods) do |
| 105 | if type(sock[v]) ~= "function" then | 105 | if type(sock[v]) ~= "function" then |
| 106 | fail(sock.class .. " method '" .. v .. "' not registered") | 106 | fail(sock.class .. " method '" .. v .. "' not registered") |
| 107 | end | 107 | end |
diff --git a/test/testmesg.lua b/test/testmesg.lua index ab85c93..04305f4 100644 --- a/test/testmesg.lua +++ b/test/testmesg.lua | |||
| @@ -12,7 +12,7 @@ source = smtp.message { | |||
| 12 | headers = { ['content-type'] = 'multipart/alternative' }, | 12 | headers = { ['content-type'] = 'multipart/alternative' }, |
| 13 | body = { | 13 | body = { |
| 14 | [1] = { | 14 | [1] = { |
| 15 | headers = { ['content-type'] = 'text/html' }, | 15 | headers = { ['Content-type'] = 'text/html' }, |
| 16 | body = "<html> <body> Hi, <b>there</b>...</body> </html>" | 16 | body = "<html> <body> Hi, <b>there</b>...</body> </html>" |
| 17 | }, | 17 | }, |
| 18 | [2] = { | 18 | [2] = { |
| @@ -60,7 +60,7 @@ source = smtp.message{ | |||
| 60 | -- chunks are loaded into memory and translation happens on the fly. | 60 | -- chunks are loaded into memory and translation happens on the fly. |
| 61 | [2] = { | 61 | [2] = { |
| 62 | headers = { | 62 | headers = { |
| 63 | ["content-type"] = 'image/png; name="luasocket.png"', | 63 | ["ConTenT-tYpE"] = 'image/png; name="luasocket.png"', |
| 64 | ["content-disposition"] = 'attachment; filename="luasocket.png"', | 64 | ["content-disposition"] = 'attachment; filename="luasocket.png"', |
| 65 | ["content-description"] = 'a beautiful image', | 65 | ["content-description"] = 'a beautiful image', |
| 66 | ["content-transfer-encoding"] = "BASE64" | 66 | ["content-transfer-encoding"] = "BASE64" |
| @@ -83,10 +83,10 @@ r, e = smtp.send{ | |||
| 83 | "<diego@princeton.edu>" }, | 83 | "<diego@princeton.edu>" }, |
| 84 | from = "<diego@princeton.edu>", | 84 | from = "<diego@princeton.edu>", |
| 85 | source = ltn12.source.chain(source, filter), | 85 | source = ltn12.source.chain(source, filter), |
| 86 | server = "mail.cs.princeton.edu", | 86 | --server = "mail.cs.princeton.edu", |
| 87 | --server = "localhost", | 87 | --port = 25 |
| 88 | --port = 2525 | 88 | server = "localhost", |
| 89 | port = 25 | 89 | port = 2525 |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | print(r, e) | 92 | print(r, e) |
