blob: fd8e09bbceef9c6e32476a80c101b68264e5d78c [file] [log] [blame]
Fred Drake21572fd1999-06-14 19:47:47 +00001\section{\module{CGIHTTPServer} ---
2 A Do-Something Request Handler}
3
4
5\declaremodule{standard}{CGIHTTPServer}
6\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
7\modulesynopsis{This module provides a request handler for HTTP servers
8 which can run CGI scripts.}
9
10
11The \module{CGIHTTPServer} module defines a request-handler class,
12interface compatible with
13\class{BaseHTTPServer.BaseHTTPRequestHandler} and inherits behaviour
14from \class{SimpleHTTPServer.SimpleHTTPRequestHandler} but can also
15run CGI scripts.
16
17The \module{CGIHTTPServer} module defines the following class:
18
19\begin{classdesc}{CGIHTTPRequestHandler}{request, client_address, server}
20This class is used to serve either files or output of CGI scripts from
21the current directory and below. Note that mapping HTTP hierarchic
22structure to local directory structure is exactly as in
23\class{SimpleHTTPServer.SimpleHTTPRequestHandler}.
24
25The class will however, run the CGI script, instead of serving it as a
26file, if it guesses it to be a CGI script. Only directory-based CGI
27are used --- the other common server configuration is to treat special
28extensions as denoting CGI scripts.
29
30The \function{do_GET()} and \function{do_HEAD()} functions are
31modified to run CGI scripts and serve the output, instead of serving
32files, if the request leads to somewhere below the
33\code{cgi_directories} path.
34\end{classdesc}
35
36The \class{CGIHTTPRequestHandler} defines the following data member:
37
38\begin{memberdesc}{cgi_directories}
39This defaults to \code{['/cgi-bin', '/htbin']} and describes
40directories to treat as containing CGI scripts.
41\end{memberdesc}
42
43The \class{CGIHTTPRequestHandler} defines the following methods:
44
45\begin{methoddesc}{do_POST}{}
46This method serves the \code{'POST'} request type, only allowed for
47CGI scripts. Error 501, "Can only POST to CGI scripts", is output
48when trying to POST to a non-CGI url.
49\end{methoddesc}
50
51Note that CGI scripts will be run with UID of user nobody, for security
52reasons. Problems with the CGI script will be translated to error 403.
53
54For example usage, see the implementation of the \function{test()}
55function.
56
57
58\begin{seealso}
59 \seemodule{BaseHTTPServer}{Base class implementation for Web server
60 and request handler.}
61\end{seealso}