lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In my search for a CGILua solution that provides SSL support, I made
some changes to the Xavante Web server code. In order to provide support
for listening on multiple ports, one has to issue multiple
xavante.HTTP{...} commands in config.lua. Unfortunately, stock Xavante
(as of Kepler-1.0b) does not save all the servers' ports.  Instead it
only stores the last one to be configured.  So if your config.lua file
has two xavante.HTTP commands, CGI scripts run by BOTH servers will use
the server port of the last one to be configured.  If the two servers
listen on different addresses but the same port, this is okay. If The
two servers listen on the same addresses but differing ports, any CGI
code run will not be able to tell which server is actually running the
script.

To fix this, make the following changes:

@@ -31,11 +31,13 @@
 -- params:
 --             skt : client socket

+function makeconnection(serverport)
 function connection (skt)
        skt:setoption ("tcp-nodelay", true)
        local req = {
                rawskt = skt,
                copasskt = copas.wrap (skt),
+               s_port = serverport,
        }
        req.socket = req.copasskt

@@ -55,6 +57,8 @@
                end
        end
 end
+return connection
+end

 -- gets and parses the request line
 -- params:
@@ -156,7 +160,7 @@
        local def_url = string.format ("http://%s%s";, req.headers.host,
req.cmd_url)

        req.parsed_url = url.parse (def_url)
-       req.parsed_url.port = req.parsed_url.port or _serverport
+       req.parsed_url.port = req.parsed_url.port or req.s_port
        req.built_url = url.build (req.parsed_url)

        local path = url.unescape (req.parsed_url.path)
@@ -318,7 +322,7 @@
        local _server = assert(socket.bind(host, port))
     _serversoftware = serversoftware
     _serverport = port
-       copas.addserver(_server, connection)
+       copas.addserver(_server, makeconnection(port))
 end

 function addHandler (host, urlpath, f)

After applying these changes, the server's port is correctly configured
in the req table, using one of my favorite Lua features, functions
returning functions. :)

Now I just gotta figure out how to get Xavante to serve the https
protocol, and I can ignore my problem with the mod2 launcher.  :)
-- 


JJS
"If Ignorance is Bliss, I'll take the Pain."