lua-users home
lua-l archive

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


On Monday 01 August 2005 5:01 pm, William Trenker wrote:
> Is there a formalized way to "communicate" between a custom Xavante
> handler and customized Cgilua handlers so that any Xavante request or
> response data can be made available to Cgilua scripts?

we haven't 'formalized' any communication between handlers and CGILua scripts.  
since any client request is finally managed by only one handler, any 
'communication' is a kind of inter-request persistence.

in Xavante, the whole environment is stable, so you could simply store data in 
a table.  in CGILua, on the other hand, each call has it's own environment; 
so the only inter-request persistence must be done via the "Stable" API.  i 
haven't tried to use it from a non-CGILua handler, but should be the easiest 
way to achieve it.

> What I'm grasping for is the best way to customize the communication
> between Xavante and Cgilua without hacking the source code.  A simple
> case is the desire to make request header values that aren't defined
> by cgilua.servervariable() available to Cgilua scripts .  For example,
> some browsers pass the http authority information (e.g. the "user:pwd"
> part of  "http://user:pwd@server:port/path";)  to the web server by
> constructing an Authorization: header.  I would like to make that
> header's value available to my Cgilua scripts to do customized
> authentication.

as by the CGI protocol definition, ALL header values supplied by the client 
are accessible by CGILua scripts, simply by making all uppercase, prepending 
'HTTP_' and replacing any '-' with '_'. so, to get the Authorization: header 
just call SAPI.Request.servervariable ("HTTP_AUTHORIZATION")

> Another example of passing data from the customized side of Xavante to
> Cgilua scripts is the match string determined by
> xavante.httpd:parse_url().  I want one of my Cgilua scripts to
> participate in decision making regarding the value of the match.
> Since Xavante puts just about everything it determines as a value in
> the req table, it would be very handy to get at it in Cgilua scripts.
> But I want to take advantage of the security of the virtual
> environment so I would like my custom Cgilua handler or open function
> to limit what xavante-provided data is passed into the Cgilua scripts.

this is interesting.  maybe we could add req/res to the SAPI record, but 
discourage its use to only when there's no other way to do it (like the match 
string).  of course it could be much cleaner to just define a "XVTE_MATCH" 
servervariable.  any opinions on that?

> In the spirit of attempting to use the design-intended user-defineable
> pieces, I've tried accessing the cgilua API (eg:
> cgilua.addopenfunction() ) from within a custom xavante handler, but I
> get an error from require"cgilua" because the SAPI table hasn't been
> defined yet. (Cgilua assumes it is being referenced by a module that
> sets up SAPI.) So this is starting to go around in circles.

this is part of what i didn't like about CGILua and moved me to write a new 
webserver: the WHOLE CGILua environment is rebuilt from zero for each 
request.  even the cgilua.addopenfunction() calls to manage both scripts and 
LuaPages are called each and every time.

> Can someone more knowledgeable give me some advice on how to maximize
> data interaction between Xavante and Cgilua in a standardized manner?

since it's all very young, what we define now might be the future 
"standardized manner"


-- 
Javier

Attachment: pgpzuo6oWuQLF.pgp
Description: PGP signature