Bash + Embedded web server

Here is copy of what I posted to .

I added shell interface to Libwebserver-0.6.0,

formatting link
which is web server library. The official version of Libwebserver is still 0.5.3, and support for that will be added soon.

Yes. You can now run embedded web server directly from shell script, totally independent of any external program. Serving out 2k file is about 7x slower than Apache. We're talking about shell script, so it's fast enough. :-)

Ref:

formatting link

Example:

hello () { echo 'Content-Type: text/plain' echo echo Hello declare -p inetname request alias_request method user pass } webserver -p 8080 -l help.log '* /h*' hello goodbye &

lynx -head -source http://localhost:8080/hxxx

Essentially, you register pairs of 'glob' and 'command' to web server:

- 'glob' will be tested against 'method' and 'uri' of the request line. So, GET /index.html HTTP/1.0 will match glob pattern * /in*

- 'command' can be anything you type on command line. So, it could be shell function, builtin command, external binary, etc.

Normally with Apache and mod_* approach, web/user interface is the main program, and your data processing application is minor sub-component. In order to interact with the remote users, you have to run as CGI, save input data to file or database, and query the saved data (maybe in another connection and process), process it, and send the result back.

With embedded approach, your data processing application is the main program, and web interface is the sub-component through which you interact with remote user. So, it's upside-down compared to Apache approach, or vice versa.

Since shell script is for processing data, the embedded approach is far better. Indeed, your shell script is now the web server. Lots of issue simply disappear, and everything has returned to its natural state of simplicity and cleanness.

Enjoy!

--
William Park , Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
	   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
	  http://freshmeat.net/projects/bashdiff/
Reply to
William Park
Loading thread data ...

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.