#!/usr/bin/q -c exit cgi_main /* $Id: myreq.q,v 1.2 2004/01/19 23:15:24 agraef Exp $ */ /* This is a little Q-CGI script which creates a page showing some information about the current request. It gathers the information from the appropriate environment variables and retrieves the request body from standard input. This works in essentially the same way no matter how the script is invoked, i.e., whether it is run through the Common Gateway Interface or directly through the Q Apache module. To try this script, copy it to a place where Apache can execute it, fire up your browser and type in the script URL (something like http://localhost/ cgi-bin/myreq.q, depending on where you put the script). You should then see a page titled "Your Request". If not, then probably you installed the script in the wrong place, or you first have to configure Apache for script execution as explained in the Apache manual. The script is useful for debugging your HTML forms, too. To these ends, just use the script URL as the ACTION field of the form, then you can see exactly which query or request body is transmitted to the server. */ /* FIXME: Are these variables documented somewhere? I compiled the following list from the API docs and traces of the subprocess_env field, so there might be some stuff missing in this list. */ def VARS = [// CGI vars: "GATEWAY_INTERFACE", "PATH_INFO", "PATH_TRANSLATED", "QUERY_STRING", "REQUEST_METHOD", "REQUEST_URI", "SCRIPT_NAME", "SERVER_PROTOCOL", // Common vars: "CONTENT_TYPE", "CONTENT_LENGTH", "HTTP_HOST", "HTTP_USER_AGENT", "HTTP_ACCEPT", "HTTP_ACCEPT_LANGUAGE", "HTTP_ACCEPT_ENCODING", "HTTP_ACCEPT_CHARSET", "HTTP_KEEP_ALIVE", "HTTP_CONNECTION", "HTTP_CACHE_CONTROL", // "SERVER_SIGNATURE", // only available when mod_q is used? "SERVER_SOFTWARE", "SERVER_NAME", "SERVER_ADDR", "SERVER_PORT", "SERVER_ADMIN", "REMOTE_HOST", "REMOTE_ADDR", "REMOTE_PORT", "REMOTE_USER", "REMOTE_IDENT", "PATH", "DOCUMENT_ROOT", "SCRIPT_FILENAME", // Only set if the request is the result of an error redirect: "REDIRECT_QUERY_STRING", "REDIRECT_URL", // Only set on Winblows: "SystemRoot", "COMSPEC", "WINDIR"], VALS = map getenv VARS; /* Templates for the header and body of the HTML page sent in the response. */ def HEADER = "Content-Type: text/html\n\n\ Your Request
\n\ Served to you by %s on %s %s.
\n", BEGIN_TABLE = "
%s | %s |
\n" || writes BEGIN_TABLE || do (printf TABLE_ROW) (filter ok (zip VARS VALS)) || writes END_TABLE || ifelse (null BODY) () (printf "
Request Body
\n
%s\n" (join "