CGI¶
CGI is a very simple process-based protocol that uses commonly available process resources:
Warning
The CGI protocol expects the response to be written in the standard output: writting there will most surely corrupt the response.
The VSGI.CGI
implementation provides a basis for its derivatives protocols
such as FastCGI and SCGI and can be used along with any HTTP
server.
The interpretation of the environment prioritize the CGI/1.1 specification
while providing fallbacks with values we typically found like REQUEST_URI
.
Since a process is spawned per request and exits when the latter finishes,
scheduled asynchronous tasks might not be processed. To overcome this issue,
hold
and release
should be used to keep the server alive as long as
necessary.
If your task involve the Request or Response in its callback, the connection will be kept alive until both are freed.
using VSGI.CGI;
Server? server = null;
ApplicationCallback app = (req, res) => {
Idle.add (() => {
message ("Hello world!");
server.release ();
});
server.hold ();
// no need to hold & release here, the reference on the request ensures
// it already
Idle.add (() => {
req.body.write_all ("Hello world!".data, null);
});
return true;
};
server = new Server ("org.vsgi.CGI", app);
server.run ();
lighttpd¶
There is an example in examples/cgi
providing a sample lighttpd
configuration file. Once launched, the application can be accessed at the
following address: http://127.0.0.1:3003/cgi-bin/app/.
lighttpd -D -f examples/cgi/lighttpd.conf