Fine tunned modules scheme.

Adjusted client modules.
Fixed proxy bug in http.
This commit is contained in:
Diego Nehab 2004-10-11 06:18:57 +00:00
parent a04f15d1ca
commit 1e5e8b5ce5
16 changed files with 46 additions and 24 deletions

2
FIX
View File

@ -1,2 +1,4 @@
gettime returns time since Unix Epoch 1/1/1970 (UTC) gettime returns time since Unix Epoch 1/1/1970 (UTC)
sleep is robust to interrupts sleep is robust to interrupts
select had a stupid bug
http.PROXY etc wasn't working

5
TODO
View File

@ -1,6 +1,5 @@
ftp.send/recv return bytes transfered?
new scheme to choose family/protocol of object to create new scheme to choose family/protocol of object to create
use new distribution scheme
fix PROXY in http.lua
change ltn13 to make sure drawbacks are obvious change ltn13 to make sure drawbacks are obvious
- check discussion - check discussion
make sure errors not thrown by try() are not caught by protect() make sure errors not thrown by try() are not caught by protect()
@ -24,6 +23,8 @@ testar os options!
- proteger ou atomizar o conjunto (timedout, receive), (timedout, send) - proteger ou atomizar o conjunto (timedout, receive), (timedout, send)
- inet_ntoa também é uma merda. - inet_ntoa também é uma merda.
*fix PROXY in http.lua
*use new distribution scheme
*create the getstats method. *create the getstats method.
*fix local domain socket kludge of name size *fix local domain socket kludge of name size
*use TLS *use TLS

View File

@ -4,8 +4,8 @@
-- Author: Diego Nehab -- Author: Diego Nehab
-- RCS ID: $Id$ -- RCS ID: $Id$
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local http = require("http") local http = require("socket.http")
local url = require("url") local url = require("socket.url")
http.TIMEOUT = 10 http.TIMEOUT = 10
function readfile(path) function readfile(path)

View File

@ -8,10 +8,10 @@ function load(s)
end end
load("socket") load("socket")
load("url") load("socket.url")
load("ltn12") load("ltn12")
load("mime") load("mime")
load("tp") load("socket.tp")
load("smtp") load("socket.smtp")
load("http") load("socket.http")
load("ftp") load("socket.ftp")

View File

@ -9,8 +9,10 @@
-- Load required modules -- Load required modules
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local socket = require("socket") local socket = require("socket")
local url = require("url") local url = require("socket.url")
local tp = require("tp") local tp = require("socket.tp")
module("socket.dict")
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Globals -- Globals

View File

@ -5,9 +5,9 @@
-- RCS ID: $Id$ -- RCS ID: $Id$
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local socket = require("socket") local socket = require("socket")
local http = require("http") local http = require("socket.http")
local ftp = require("ftp") local ftp = require("socket.ftp")
local url = require("url") local url = require("socket.url")
local ltn12 = require("ltn12") local ltn12 = require("ltn12")
-- formats a number of seconds into human readable form -- formats a number of seconds into human readable form

View File

@ -39,7 +39,6 @@ local function connect(localhost, option)
until localport > 731 until localport > 731
test(skt, err) test(skt, err)
else skt = test(socket.tcp()) end else skt = test(socket.tcp()) end
print("'" .. host .. "'")
try(skt:connect(host, port)) try(skt:connect(host, port))
return { skt = skt, try = try } return { skt = skt, try = try }
end end

View File

@ -10,7 +10,9 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local socket = require("socket") local socket = require("socket")
local ltn12 = require("ltn12") local ltn12 = require("ltn12")
local url = require("url") local url = require("socket.url")
module("socket.tftp")
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Program constants -- Program constants

View File

@ -1,5 +1,5 @@
local socket = require("socket") local socket = require("socket")
local http = require("http") local http = require("socket.http")
if not arg or not arg[1] or not arg[2] then if not arg or not arg[1] or not arg[2] then
print("luasocket cddb.lua <category> <disc-id> [<server>]") print("luasocket cddb.lua <category> <disc-id> [<server>]")

View File

@ -1,4 +1,4 @@
local lp = require("lp") local lp = require("socket.lp")
local function usage() local function usage()
print('\nUsage: lua lptest.lua [filename] [keyword=val...]\n') print('\nUsage: lua lptest.lua [filename] [keyword=val...]\n')

View File

@ -113,8 +113,9 @@ end
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- High level HTTP API -- High level HTTP API
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local function uri(reqt) local function adjusturi(reqt)
local u = reqt local u = reqt
-- if there is a proxy, we need the full url. otherwise, just a part.
if not reqt.proxy and not PROXY then if not reqt.proxy and not PROXY then
u = { u = {
path = socket.try(reqt.path, "invalid path 'nil'"), path = socket.try(reqt.path, "invalid path 'nil'"),
@ -126,6 +127,16 @@ local function uri(reqt)
return url.build(u) return url.build(u)
end end
local function adjustproxy(reqt)
local proxy = reqt.proxy or PROXY
if proxy then
proxy = url.parse(proxy)
return proxy.host, proxy.port or 3128
else
return reqt.host, reqt.port
end
end
local function adjustheaders(headers, host) local function adjustheaders(headers, host)
local lower = {} local lower = {}
-- override with user values -- override with user values
@ -152,7 +163,9 @@ local function adjustrequest(reqt)
for i,v in reqt do nreqt[i] = reqt[i] end for i,v in reqt do nreqt[i] = reqt[i] end
socket.try(nreqt.host, "invalid host '" .. tostring(nreqt.host) .. "'") socket.try(nreqt.host, "invalid host '" .. tostring(nreqt.host) .. "'")
-- compute uri if user hasn't overriden -- compute uri if user hasn't overriden
nreqt.uri = nreqt.uri or uri(nreqt) nreqt.uri = reqt.uri or adjusturi(nreqt)
-- ajust host and port if there is a proxy
nreqt.host, nreqt.port = adjustproxy(nreqt)
-- adjust headers in request -- adjust headers in request
nreqt.headers = adjustheaders(nreqt.headers, nreqt.host) nreqt.headers = adjustheaders(nreqt.headers, nreqt.host)
return nreqt return nreqt

View File

@ -19,7 +19,7 @@
\*=========================================================================*/ \*=========================================================================*/
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <compat-5.1.h> #include "compat-5.1.h"
/*=========================================================================*\ /*=========================================================================*\
* LuaSocket includes * LuaSocket includes

View File

@ -8,7 +8,7 @@
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <compat-5.1.h> #include "compat-5.1.h"
#include "mime.h" #include "mime.h"

3
test/dicttest.lua Normal file
View File

@ -0,0 +1,3 @@
local dict = require"socket.dict"
for i,v in dict.get("dict://localhost/d:banana") do print(v) end

View File

@ -1,5 +1,5 @@
-- load tftpclnt.lua -- load tftpclnt.lua
local tftp = require("tftp") local tftp = require("socket.tftp")
-- needs tftp server running on localhost, with root pointing to -- needs tftp server running on localhost, with root pointing to
-- a directory with index.html in it -- a directory with index.html in it

View File

@ -1,5 +1,5 @@
local socket = require("socket") local socket = require("socket")
socket.url = require("url") socket.url = require("socket.url")
dofile("testsupport.lua") dofile("testsupport.lua")
local check_build_url = function(parsed) local check_build_url = function(parsed)