В Wed, 22 Dec 2010 12:14:31 +0100
Nicolas Cannasse <[email protected]> пишет:
> Le 22/12/2010 11:48, Alexander Konotop a écrit :
> > Hello. Does anyone have experience in using neko as a web backend
> > without apache? I have set it up in lighttpd and even in IIS.
> > Everything's good but HTTP input data - I can't recieve POST/GET.
> >
> > 1. That's how simply lighttpd handles neko:
> > server.modules += ( "mod_cgi" )
> > cgi.assign = ( ".n" => "/usr/bin/neko" )
> > And that's all I've done in server config.
> >
> > 2. Code in haxe:
> > //Gettest.hx
> > class Gettest {
> > public static function main()
> > {
> > trace(neko.Web.getParamsString());
> > }
> > }
> > //gettest.hxml
> > -neko gettest.n
> > -main Gettest.hx
> >
> > 3. CGI output:
> > // http://localhost/nekocgi/gettest/gettest.n?a=2
> > Gettest.hx:5:
> > // nothing?
> >
> > 4. nekotools server output:
> > // http://localhost:2000/gettest.n?a=123&b=1234
> > Gettest.hx:5: a=123&b=1234
> >
> > In truth I do not understand how nekoserver redirects
> > POST/GET data to nekovm. So I don't understand how to make another
> > server (nginx, lighttpd, IIS, or any other) do the same.
> > In the case of mod_neko everything's clear: mod_neko is a part of
> > apache.
> > Last time I started thinking about using nekoserver as a backend and
> > lighty as a frontend (same way as a popular combination of
> > nginx+apache). But nekoserver isn't known to be recommended on a
> > production server.
> > So what can you advice? Not to waste time and install apache? I
> > don't like it... And what can you say about performance in CGI
> > mode? In case of (for example) Perl every time when request comes
> > to a web-server the interpreter is loading from HDD to memory, so
> > CGI is slow. But neko is really small!!! So I thought it will be
> > quiet fast. Am I wrong?
>
> CGI runs commands, so your web server will run the following command :
>
> neko /absolute/path/to/gettest.n
> http://localhost/nekocgi/gettest/gettest.n?a=2
>
> If you look at neko.Web implementation (in haxe/std/neko/Web.hx)
> you'll see that if neko is not run from inside mod_neko, it will use
> the first argument as URL. This has not been tested a lot, but should
> work.
>
> I wonder how CGI sends POST data, maybe through environment
> variables ? Try printing neko.Sys.environment()
>
> Nicolas
>
Did You mean this code in Web.hx (haxe
v.2.05 /usr/share/haxe/neko/Web.hx lines 348-356)?
==========================
} else {
var a0 = untyped __dollar__loader.args[0];
if( a0 != null ) a0 = new String(a0);
_set_main = function(f) { };
_get_host_name = function() { return untyped
"localhost".__s; }; _get_client_ip = function() { return untyped
"127.0.0.1".__s; }; _get_uri = function() {
return untyped (if( a0 == null ) "/"
else a0).__s; };
==========================
I can't see a params parse code here but it seems to work for
nekoserver and not to work with lighttpd. (I mean GET).
Printing environment variables:
New code:
class Gettest {
public static function main()
{
neko.Lib.print(neko.Sys.environment());
neko.Lib.print("\n\n");
trace(neko.Web.getParamsString());
}
}
-----------------------
1. lighttpd output:
// http://localhost/nekocgi/gettest/gettest.n?a=2&b=3
{HTTP_CONNECTION => keep-alive, REQUEST_METHOD => GET, REDIRECT_STATUS
=> 200, REMOTE_PORT => 47178, SERVER_ADDR => 0.0.0.0, HTTP_HOST =>
localhost, HTTP_CACHE_CONTROL => max-age=0, HTTP_ACCEPT_CHARSET =>
UTF-8,*;q=0.5, SERVER_NAME => localhost, SERVER_PORT => 80,
HTTP_ACCEPT_ENCODING => gzip,deflate,sdch, GATEWAY_INTERFACE =>
CGI/1.1, SERVER_PROTOCOL => HTTP/1.1, REQUEST_URI
=> /nekocgi/gettest/gettest.n?a=2&b=3, CONTENT_LENGTH => 0,
HTTP_USER_AGENT => Mozilla/5.0 (X11; U; Linux x86_64; en-US)
AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3,
SCRIPT_NAME => /nekocgi/gettest/gettest.n, HTTP_ACCEPT =>
application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5,
SERVER_SOFTWARE => lighttpd/1.4.28, SCRIPT_FILENAME
=> /var/www/nekocgi/gettest/gettest.n, QUERY_STRING => a=2&b=3,
REMOTE_ADDR => 127.0.0.1, DOCUMENT_ROOT => /var/www,
HTTP_ACCEPT_LANGUAGE => ru,uk;q=0.8,en;q=0.6,en-US;q=0.4}
2. nekotools server output:
http://localhost:2000/gettest.n?a=2&b=3
{DESKTOP_SESSION => xfce, COLORTERM => Terminal, LANG => ru_RU.utf8,
GDMSESSION => xfce, GLADE_CATALOG_PATH => :/usr/share/glade3/catalogs,
SSH_AUTH_SOCK => /tmp/ssh-nvlLnR2299/agent.2299, MOD_NEKO => 1, LOGNAME
=> fashist, WINDOWPATH => 7, LIBGLADE_MODULE_PATH
=> :/usr/lib/libglade/2.0, GTK_PATH => :/usr/lib/gtk-2.0, DISPLAY
=> :0.0, PWD => /var/www/nekocgi/gettest, USERNAME => fashist, HOME
=> /home/fashist, SESSION_MANAGER =>
local/jager:@/tmp/.ICE-unix/2369,unix/jager:/tmp/.ICE-unix/2369, PATH
=> /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games, _
=> /usr/bin/nekotools, GLADE_MODULE_PATH => :/usr/lib/glade3/modules,
TERM => xterm, XDG_SESSION_COOKIE =>
9465a5fc37a12cf638ddca2900000035-1293008953.729919-396646087,
XDG_DATA_DIRS
=> /usr/local/share/:/usr/share/:/usr/share/gdm/:/usr/share,
SSH_AGENT_PID => 2344, WINDOWID => 69221071, SHELL => /bin/bash,
LS_COLORS =>
rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:,
GDM_XSERVER_LOCATION => local, DBUS_SESSION_BUS_ADDRESS =>
unix:abstract=/tmp/dbus-hv2W62SHav,guid=a245ad2719ba858ecb01dfd300000028,
GLADE_PIXMAP_PATH => :/usr/share/glade3/pixmaps, USER => fashist, SHLVL
=> 1, XAUTHORITY => /home/fashist/.Xauthority} Gettest.hx:6: a=2&b=3
-----------------------
What do we see here? LIGHTTPD PUSHES GET_PARAMS TO NEKO!!! COOL! But
seems that it does it in other way than nekotools server. So, I could
parse the HTTP headers myself, but getParamsString() doesn't work.
It's about GET: it works normally in nekotools server but it doesn't
work neither in lighttpd nor in iis.
POST protocol I will check later today or tomorrow and sureley will send
results.
--
Neko : One VM to run them all
(http://nekovm.org)