sunlabs.brazil.handler
Class CgiHandler
public
class
CgiHandler
extends Object
implements Handler
Handler for implementing cgi/1.1 interface.
This implementation allows either suffix matching (e.g. .cgi) to identify
cgi scripts, or prefix matching (e.g. /bgi-bin). Defaults to "/".
All output from the cgi script is buffered (e.g. chunked encoding is
not supported).
NOTE: in versions of Java prior to release 1.3, the ability to set
a working directory when running an external process is missing.
This handler automatically checks for this ability and sets the
proper working directory, but only if the underlying VM supports it.
The following request properties are used:
- root
- The document root for cgi files
- suffix
- The suffix for cgi files (defaults to .cgi)
- prefix
- The prefix for all cgi files (e.g. /cgi-bin)
- url
- "o(riginal)" or "c(urrent)".
If an upstream handler has changed the URL, this specifes
which url to look for the cgi script relative to. The default
is to use the original url.
- custom
- set to "true" to enable custom environment variables.
If set, all server properties starting with this handler's
prefix are placed into the environment with the name:
CONFIG_name
, where name is the
property key, in upper case, with the prefix removed.
This allows cgi scripts to be customized in the server's
configuration file.
- runwith
- The command to use to run scripts.
The absolute file path is added as the last
parameter. If not specified, the file name is run as the
command.
- noheaders
-
According to the CGI spec, cgi documents are to begin with
properly formed http headers to specifie the type, return status
and optionally other meta information about the request.
if "noheaders" is specified, then the content is expected
to *not* have any http headers, and the content type is
as implied by the url suffix.
See example configuration in the samples included with the distribution.
Version: 2.4, 06/06/14
Author: Stephen Uhler
public CgiHandler()
construct table of CGI environment variables that need special handling
public boolean init(
Server server, String prefix)
One time initialization. The handler configuration properties are
extracted and set in
respond to allow
upstream handlers to modify the parameters.
public boolean respond(
Request request)
Dispatch and handle the CGI request. Gets called on ALL requests.
Set up the environment, exec the process, and deal
appropriately with the input and output.
In this implementation, all cgi script files must end with a
standard suffix, although the suffix may omitted from the url.
The url /main/do/me/too?a=b will look, starting in DocRoot,
for main.cgi, main/do.cgi, etc until a matching file is found.
Input parameters examined in the request properties:
- Suffix
- The suffix for all cgi scripts (defaults to .cgi)
- DocRoot
- The document root, for locating the script.