mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-07-24 01:39:49 +02:00
Fine tunned modules scheme.
Adjusted client modules. Fixed proxy bug in http.
This commit is contained in:
17
src/http.lua
17
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
|
||||
|
@ -19,7 +19,7 @@
|
||||
\*=========================================================================*/
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <compat-5.1.h>
|
||||
#include "compat-5.1.h"
|
||||
|
||||
/*=========================================================================*\
|
||||
* LuaSocket includes
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <compat-5.1.h>
|
||||
#include "compat-5.1.h"
|
||||
|
||||
#include "mime.h"
|
||||
|
||||
|
Reference in New Issue
Block a user