diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/http.lua | 17 | ||||
-rw-r--r-- | src/luasocket.c | 2 | ||||
-rw-r--r-- | src/mime.c | 2 |
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 | ----------------------------------------------------------------------------- |
116 | local function uri(reqt) | 116 | local 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) |
127 | end | 128 | end |
128 | 129 | ||
130 | local 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 | ||
138 | end | ||
139 | |||
129 | local function adjustheaders(headers, host) | 140 | local 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 |
@@ -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 | ||