Io Reference







Networking   /   CGI   /   CGI





CGI supports accessing CGI parameters passed in environment variables or standard input by a web servers like Apache. Example use:
#!./ioServer

cgi = CGI clone

redirect = cgi getParameters at("redirurl")
if (redirect and redirect != "",
	redirect clipAfterStartOfSeq("\r")
	redirect clipAfterStartOfSeq("\n")
	cgi redirect(redirect)
	System exit(0)
 )

cgi header("Content-type", "text/html")

cgi write("<html><head><title>test</title><body>")
cgi write("GET Parameters:")
cgi getParameters foreach(k, v,
	cgi write(k .. " = " .. v .. ","))
)

cgi write("POST Parameters:")
cgi postParameters foreach(k, v,
	cgi write(k .. " = " .. v .. ","))
)

cgi write("COOKIES:")
cgi cookies foreach(k, v,
	cgi write(k .. " = " .. v .. ",")
)
 
 
 



contentLength

CONTENT_LENGTH from web server - Size of POST Data
contentType

CONTENT_TYPE from web server
cookies

Returns a Map of cookies provided by the client
decodeUrlParam(aString)

Returns a URL decoded version of aString.
encodeUrlParam(aString)

Returns a URL encoded version of aString.
getParameters

Parses the QUERY_STRING environment variable and returns a Map containing key/value query value pairs. For testing, a QUERY_STRING can be passed to standard in, one line will be read
header(name, value, sendMultiple)

Add a header to the output, may only be called before write() is called. One of each header will be sent unless sendMultiple is true
httpHeader(name)

Fetch a header supplied by the client, such as 'referer'
isInWebScript

Checks to see if this is being called within a CGI request or from the command-line (testing). Simply checks for System getEnvironmentVariable("GATEWAY_INTERFACE")
maxPostSize

Maximum size in bytes, to process from user submitted data. Data greater than this will result in a nil postData slot
maxPostSizeExceeded

Returns true if the POST data exceeds a set maxPostSize
pathInfo

PATH_INFO from web server
pathTranslated

PATH_TRANSLATED from web server
postData

The raw post data sent to the script. Only set if getEnvironmentVariable("REQUEST_METHOD") asLowercase == "post".
postParameters

Parses the POST data, multipart and urlencoded. Returns a map of submitted variables. For uploaded files, an Object is returned with these slots:
fileName
content (raw content of file as Sequence)
contentType
contentEncoding
size (in characters/bytes)
asString (pretty string of name, type, size)
queryString

QUERY_STRING from web server
redirect(url)

Send a location: and redirect the user. May only be called before write() is called. It is left to the caller to stop any further processing.
remoteAddress

REMOTE_ADDR from web server - User's IP
remoteHost

REMOTE_HOST from web server - User's host (often blank)
requestMethod

GET, POST, PUT, etc
requestParameter(name)

Lazy developer's helper funtion. Retrieves a value from GET or POST, POST first
scriptName

SCRIPT_NAME from web server
setCookie(name, value, expiresDate, domain, path, secureBool)

Sets a cookie, keep in mind this will not be available in cookies() until they next visit to the site. Parameters other than name and value are optional.
status(statusCode)

Numeric status code to send to the client. Normally, the server will figure this out on its own, but this allows handling 404s and such.
write(string, [string...])

Send content for the body of the response