Introduction into OcamlNet
 Component "netstring"
Component "cgi"
 Netcgi
 Advanced connectors
 General hints


RELATED
Reference Manual
   
The library component "cgi"

OcamlNet implements CGI, i.e. it is possible that web servers call O'Caml programs (web applications) to serve web requests. There are even two implementations, an old one (module Cgi) and a new one (the Netcgi modules). Of course, the new implementation should be preferred in new programs, and we explain only this version here.

The new implementation supports even non-standard connections between web servers and web applications. The classic CGI method is quite flexible, but it has performance limits. There are better methods, but they need special support both in the web server and in the web application. From the existing high-performance connection methods the JSERV/Tomcat protocol has been selected, mostly because it is very simple, and there are implementations for many web servers.

Summarized, the Netcgi modules support the following features:

  • The CGI/1.1 protocol is fully supported.

  • The Ajp/1.2 protocol (used by JSERV and Tomcat) is supported. Requests can be processed sequentially (one worker process), by forked subprocesses (one master process, one worker subprocess per request), or by pre-forked subprocesses (one master process, and a pool of subprocesses waiting for work). There is currently no support for multi-threaded web applications yet (but there is a demo that shows how that could work).

  • CGI parameters can be decoded and encoded. All methods of passing CGI parameters are implemented: GET/URL-encoded, POST/URL-encoded and POST/form-encoded. The latter method must be used for file uploads, which are supported. File uploads can be processed chunk by chunk, and thus uploaded files can be directly stored in the filesystem, avoiding large memory allocations.

  • Cookies are supported.

  • Generated contents can be directly sent back, or they can be buffered until it is clear that no error has happened (web transactions)

  • Cache-control directives can be generated.

  • It is possible to limit the size of CGI parameters

  • Missing features: No support for non-parsed headers, for server push, and for exotic features like multipart file upload

  • Out of scope: This library does neither deal with methods to generate contents, nor how to manage application state