aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-10-11 06:18:57 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-10-11 06:18:57 +0000
commit1e5e8b5ce5573fddc7060dae3c1bf2c02788b35a (patch)
tree35012ac4464bf4a3c8ed942495ef37319b6c9ad1 /src
parenta04f15d1ca440006a53bd0d9f98c12e5abebd969 (diff)
downloadluasocket-1e5e8b5ce5573fddc7060dae3c1bf2c02788b35a.tar.gz
luasocket-1e5e8b5ce5573fddc7060dae3c1bf2c02788b35a.tar.bz2
luasocket-1e5e8b5ce5573fddc7060dae3c1bf2c02788b35a.zip
Fine tunned modules scheme.
Adjusted client modules. Fixed proxy bug in http.
Diffstat (limited to 'src')
-rw-r--r--src/http.lua17
-rw-r--r--src/luasocket.c2
-rw-r--r--src/mime.c2
3 files changed, 17 insertions, 4 deletions
diff --git a/src/http.lua b/src/http.lua
index 8ea4c47..b265650 100644
--- a/src/http.lua
+++ b/src/http.lua
@@ -113,8 +113,9 @@ end
113----------------------------------------------------------------------------- 113-----------------------------------------------------------------------------
114-- High level HTTP API 114-- High level HTTP API
115----------------------------------------------------------------------------- 115-----------------------------------------------------------------------------
116local function uri(reqt) 116local function adjusturi(reqt)
117 local u = reqt 117 local u = reqt
118 -- if there is a proxy, we need the full url. otherwise, just a part.
118 if not reqt.proxy and not PROXY then 119 if not reqt.proxy and not PROXY then
119 u = { 120 u = {
120 path = socket.try(reqt.path, "invalid path 'nil'"), 121 path = socket.try(reqt.path, "invalid path 'nil'"),
@@ -126,6 +127,16 @@ local function uri(reqt)
126 return url.build(u) 127 return url.build(u)
127end 128end
128 129
130local function adjustproxy(reqt)
131 local proxy = reqt.proxy or PROXY
132 if proxy then
133 proxy = url.parse(proxy)
134 return proxy.host, proxy.port or 3128
135 else
136 return reqt.host, reqt.port
137 end
138end
139
129local function adjustheaders(headers, host) 140local function adjustheaders(headers, host)
130 local lower = {} 141 local lower = {}
131 -- override with user values 142 -- override with user values
@@ -152,7 +163,9 @@ local function adjustrequest(reqt)
152 for i,v in reqt do nreqt[i] = reqt[i] end 163 for i,v in reqt do nreqt[i] = reqt[i] end
153 socket.try(nreqt.host, "invalid host '" .. tostring(nreqt.host) .. "'") 164 socket.try(nreqt.host, "invalid host '" .. tostring(nreqt.host) .. "'")
154 -- compute uri if user hasn't overriden 165 -- compute uri if user hasn't overriden
155 nreqt.uri = nreqt.uri or uri(nreqt) 166 nreqt.uri = reqt.uri or adjusturi(nreqt)
167 -- ajust host and port if there is a proxy
168 nreqt.host, nreqt.port = adjustproxy(nreqt)
156 -- adjust headers in request 169 -- adjust headers in request
157 nreqt.headers = adjustheaders(nreqt.headers, nreqt.host) 170 nreqt.headers = adjustheaders(nreqt.headers, nreqt.host)
158 return nreqt 171 return nreqt
diff --git a/src/luasocket.c b/src/luasocket.c
index ebe9f5f..d07b90f 100644
--- a/src/luasocket.c
+++ b/src/luasocket.c
@@ -19,7 +19,7 @@
19\*=========================================================================*/ 19\*=========================================================================*/
20#include <lua.h> 20#include <lua.h>
21#include <lauxlib.h> 21#include <lauxlib.h>
22#include <compat-5.1.h> 22#include "compat-5.1.h"
23 23
24/*=========================================================================*\ 24/*=========================================================================*\
25* LuaSocket includes 25* LuaSocket includes
diff --git a/src/mime.c b/src/mime.c
index 594135f..8bc20d3 100644
--- a/src/mime.c
+++ b/src/mime.c
@@ -8,7 +8,7 @@
8 8
9#include <lua.h> 9#include <lua.h>
10#include <lauxlib.h> 10#include <lauxlib.h>
11#include <compat-5.1.h> 11#include "compat-5.1.h"
12 12
13#include "mime.h" 13#include "mime.h"
14 14