diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-03-10 02:15:04 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-03-10 02:15:04 +0000 |
| commit | 63e3d7c5b0886a4243dd426b2a9f58d2173b26cf (patch) | |
| tree | 998f11b31c46e4f53b7206bd2bf7417745b321a3 /src | |
| parent | b18021e22d5c192c88372889def02e6edb21b5be (diff) | |
| download | luasocket-63e3d7c5b0886a4243dd426b2a9f58d2173b26cf.tar.gz luasocket-63e3d7c5b0886a4243dd426b2a9f58d2173b26cf.tar.bz2 luasocket-63e3d7c5b0886a4243dd426b2a9f58d2173b26cf.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/http.lua | 28 |
1 files changed, 21 insertions, 7 deletions
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 | |||
| 32 | ----------------------------------------------------------------------------- | 32 | ----------------------------------------------------------------------------- |
| 33 | local metat = { __index = {} } | 33 | local metat = { __index = {} } |
| 34 | 34 | ||
| 35 | function open(host, port) | 35 | -- default connect function, respecting the timeout |
| 36 | local c = socket.try(socket.tcp()) | 36 | local function connect(host, port) |
| 37 | local c, e = socket.tcp() | ||
| 38 | if not c then return nil, e end | ||
| 39 | c:settimeout(TIMEOUT) | ||
| 40 | local r, e = c:connect(host, port or PORT) | ||
| 41 | if not r then | ||
| 42 | c:close() | ||
| 43 | return nil, e | ||
| 44 | end | ||
| 45 | return c | ||
| 46 | end | ||
| 47 | |||
| 48 | function open(host, port, user) | ||
| 49 | -- create socket with user connect function, or with default | ||
| 50 | local c = socket.try((user or connect)(host, port)) | ||
| 51 | -- create our http request object, pointing to the socket | ||
| 37 | local h = base.setmetatable({ c = c }, metat) | 52 | local h = base.setmetatable({ c = c }, metat) |
| 38 | -- make sure the connection gets closed on exception | 53 | -- make sure the object close gets called on exception |
| 39 | h.try = socket.newtry(function() h:close() end) | 54 | h.try = socket.newtry(function() h:close() end) |
| 40 | h.try(c:settimeout(TIMEOUT)) | ||
| 41 | h.try(c:connect(host, port or PORT)) | ||
| 42 | return h | 55 | return h |
| 43 | end | 56 | end |
| 44 | 57 | ||
| @@ -215,13 +228,14 @@ function tredirect(reqt, headers) | |||
| 215 | sink = reqt.sink, | 228 | sink = reqt.sink, |
| 216 | headers = reqt.headers, | 229 | headers = reqt.headers, |
| 217 | proxy = reqt.proxy, | 230 | proxy = reqt.proxy, |
| 218 | nredirects = (reqt.nredirects or 0) + 1 | 231 | nredirects = (reqt.nredirects or 0) + 1, |
| 232 | connect = reqt.connect | ||
| 219 | } | 233 | } |
| 220 | end | 234 | end |
| 221 | 235 | ||
| 222 | function trequest(reqt) | 236 | function trequest(reqt) |
| 223 | reqt = adjustrequest(reqt) | 237 | reqt = adjustrequest(reqt) |
| 224 | local h = open(reqt.host, reqt.port) | 238 | local h = open(reqt.host, reqt.port, reqt.connect) |
| 225 | h:sendrequestline(reqt.method, reqt.uri) | 239 | h:sendrequestline(reqt.method, reqt.uri) |
| 226 | h:sendheaders(reqt.headers) | 240 | h:sendheaders(reqt.headers) |
| 227 | h:sendbody(reqt.headers, reqt.source, reqt.step) | 241 | h:sendbody(reqt.headers, reqt.source, reqt.step) |
