From 63e3d7c5b0886a4243dd426b2a9f58d2173b26cf Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Thu, 10 Mar 2005 02:15:04 +0000 Subject: Forward server works for multiple tunnels. Http.lua has been patched to support non-blocking everything. Makefile for linux has been updated with new names. --- src/http.lua | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/http.lua b/src/http.lua index 1dff11a..38b93e2 100644 --- a/src/http.lua +++ b/src/http.lua @@ -32,13 +32,26 @@ USERAGENT = socket.VERSION ----------------------------------------------------------------------------- local metat = { __index = {} } -function open(host, port) - local c = socket.try(socket.tcp()) +-- default connect function, respecting the timeout +local function connect(host, port) + local c, e = socket.tcp() + if not c then return nil, e end + c:settimeout(TIMEOUT) + local r, e = c:connect(host, port or PORT) + if not r then + c:close() + return nil, e + end + return c +end + +function open(host, port, user) + -- create socket with user connect function, or with default + local c = socket.try((user or connect)(host, port)) + -- create our http request object, pointing to the socket local h = base.setmetatable({ c = c }, metat) - -- make sure the connection gets closed on exception + -- make sure the object close gets called on exception h.try = socket.newtry(function() h:close() end) - h.try(c:settimeout(TIMEOUT)) - h.try(c:connect(host, port or PORT)) return h end @@ -215,13 +228,14 @@ function tredirect(reqt, headers) sink = reqt.sink, headers = reqt.headers, proxy = reqt.proxy, - nredirects = (reqt.nredirects or 0) + 1 + nredirects = (reqt.nredirects or 0) + 1, + connect = reqt.connect } end function trequest(reqt) reqt = adjustrequest(reqt) - local h = open(reqt.host, reqt.port) + local h = open(reqt.host, reqt.port, reqt.connect) h:sendrequestline(reqt.method, reqt.uri) h:sendheaders(reqt.headers) h:sendbody(reqt.headers, reqt.source, reqt.step) -- cgit v1.2.3-55-g6feb