From 1e5e8b5ce5573fddc7060dae3c1bf2c02788b35a Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Mon, 11 Oct 2004 06:18:57 +0000 Subject: Fine tunned modules scheme. Adjusted client modules. Fixed proxy bug in http. --- src/http.lua | 17 +++++++++++++++-- src/luasocket.c | 2 +- src/mime.c | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src') 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 ----------------------------------------------------------------------------- -- High level HTTP API ----------------------------------------------------------------------------- -local function uri(reqt) +local function adjusturi(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 u = { path = socket.try(reqt.path, "invalid path 'nil'"), @@ -126,6 +127,16 @@ local function uri(reqt) return url.build(u) 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 lower = {} -- override with user values @@ -152,7 +163,9 @@ local function adjustrequest(reqt) for i,v in reqt do nreqt[i] = reqt[i] end socket.try(nreqt.host, "invalid host '" .. tostring(nreqt.host) .. "'") -- 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 nreqt.headers = adjustheaders(nreqt.headers, nreqt.host) 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 @@ \*=========================================================================*/ #include #include -#include +#include "compat-5.1.h" /*=========================================================================*\ * 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 @@ #include #include -#include +#include "compat-5.1.h" #include "mime.h" -- cgit v1.2.3-55-g6feb