CGI stands for Common Gateway Interface and it is a standardized mechanism to
call scripts from the server.
The term script is abused: it stands for interpreted languages macros as well
for high level language compiled executables.
hserv offers a quite complete interface to CGI/1.0.
Script types are restricted to:
- ARexx macros
- Perl scripts
- Rebol scripts
- AmigaOS executables
The concept of nph script is not supported by hserv.
The type of the macro is parsed from its file name extension:
- ARexx macros must have the extension rexx
- Perl CGI macros must have the extension cgi, pl or sh
- Rebol macros must have the extension r
- AmigaOS executables must have no extension
The type of a macro may be overwritten with an entry in Handlers file.
The Handlers file consists of lines in the form
<pattern> <handler>
| pattern |
An AmigaDOS pattern applied to the requested
script. |
| handler |
One of:
- REXX: consider the script an ARexx macro
- REBOL: consider the script a REBOL script
- PERL: consider the script a PERL macro
- EXE: consider the script a compiled executable
- SEND: just send the script as application/octet
|
A CGI will be execute if and only if the option DISABLECGI is not set.
A Perl script will be execute if and only if the option PERLPATH is defined and its
value is a complete path to perl or sh or whatever.
A Rebol script will be execute if and only if the option REBOLPATH is defined and its
value is a complete path to Rebol.
CGI scripts derive arguments in this way:
- the query string is passed in the command line
E.g. if the requested url is
http://www.alfie.org/cgi-bin/script.rexx?cmd=query
the query string is cmd=query
the query string is URL-encoded
- if the method is POST, the content is availble in the STDIN
- other arguments are defined as local variables in the process. They may be got
with:
- ARexx:
GetVar(name,"local")
- Perl:
$ENV{name}
- SH:
$name
- Rebol:
/system/options/cgi/name
- C:
GetVar(name,buf,size of(buf),GVF_LOCAL_ONLY)
The avaible arguments are:
- ARexx, Perl and AmigaOS executable
- AUTH_TYPE
- CLIENT_SOFTWARE
- CONTENT_LENGTH
- CONTENT_TYPE
- DOCUMENT_ROOT
- GATEWAY_INTERFACE
- HTTP_ACCEPT
- HTTP_REFERER
- HTTP_USER_AGENT
- PATH_INFO
- PATH_TRANSLATED
- QUERY_STRING
- REMOTE_ADDR
- REMOTE_HOST
- REMOTE_IDENT
- REMOTE_USER
- REQUEST_METHOD
- SCRIPT_NAME
- SERVER_NAME
- SERVER_PORT
- SERVER_PROTOCOL
- SERVER_SOFTWARE
- Rebol
- system/options/cgi/server-software
- system/options/cgi/server-name
- system/options/cgi/gateway-interface
- system/options/cgi/server-protocol
- system/options/cgi/server-port
- system/options/cgi/request-method
- system/options/cgi/path-info
- system/options/cgi/path-translated
- system/options/cgi/script-name
- system/options/cgi/query-string
- system/options/cgi/remote-host
- system/options/cgi/remote-addr
- system/options/cgi/auth-type
- system/options/cgi/remote-user
- system/options/cgi/remote-ident
- system/options/cgi/Content-Type
- system/options/cgi/content-length
Scripts must write to stdout:
- first line:
Content-Type: mime
- second line: (empty)
- rest: data (mime specific)
Other non empty lines after Content-Type: mime are discarded.