blob: 3381c64e4a0d82e801db17577e3565aad1819fb2 [file] [log] [blame]
Fred Drake21572fd1999-06-14 19:47:47 +00001\section{\module{CGIHTTPServer} ---
Fred Drake4d3714b2000-10-10 16:56:41 +00002 CGI-capable HTTP request handler}
Fred Drake21572fd1999-06-14 19:47:47 +00003
4
5\declaremodule{standard}{CGIHTTPServer}
Fred Drake57657bc2000-12-01 15:25:23 +00006\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
Fred Drake21572fd1999-06-14 19:47:47 +00007\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
Thomas Woutersf8316632000-07-16 19:01:10 +000013\class{BaseHTTPServer.BaseHTTPRequestHandler} and inherits behavior
Fred Drake21572fd1999-06-14 19:47:47 +000014from \class{SimpleHTTPServer.SimpleHTTPRequestHandler} but can also
15run CGI scripts.
16
Fred Drakee70dbe02001-11-19 05:16:35 +000017\note{This module can run CGI scripts on \UNIX{} and Windows systems;
18on Mac OS it will only be able to run Python scripts within the same
19process as itself.}
Fred Drake38e5d272000-04-03 20:13:55 +000020
Fred Drake21572fd1999-06-14 19:47:47 +000021The \module{CGIHTTPServer} module defines the following class:
22
23\begin{classdesc}{CGIHTTPRequestHandler}{request, client_address, server}
24This class is used to serve either files or output of CGI scripts from
25the current directory and below. Note that mapping HTTP hierarchic
26structure to local directory structure is exactly as in
27\class{SimpleHTTPServer.SimpleHTTPRequestHandler}.
28
29The class will however, run the CGI script, instead of serving it as a
30file, if it guesses it to be a CGI script. Only directory-based CGI
31are used --- the other common server configuration is to treat special
32extensions as denoting CGI scripts.
33
34The \function{do_GET()} and \function{do_HEAD()} functions are
35modified to run CGI scripts and serve the output, instead of serving
36files, if the request leads to somewhere below the
37\code{cgi_directories} path.
38\end{classdesc}
39
40The \class{CGIHTTPRequestHandler} defines the following data member:
41
42\begin{memberdesc}{cgi_directories}
43This defaults to \code{['/cgi-bin', '/htbin']} and describes
44directories to treat as containing CGI scripts.
45\end{memberdesc}
46
47The \class{CGIHTTPRequestHandler} defines the following methods:
48
49\begin{methoddesc}{do_POST}{}
50This method serves the \code{'POST'} request type, only allowed for
51CGI scripts. Error 501, "Can only POST to CGI scripts", is output
52when trying to POST to a non-CGI url.
53\end{methoddesc}
54
55Note that CGI scripts will be run with UID of user nobody, for security
56reasons. Problems with the CGI script will be translated to error 403.
57
58For example usage, see the implementation of the \function{test()}
59function.
60
61
62\begin{seealso}
63 \seemodule{BaseHTTPServer}{Base class implementation for Web server
64 and request handler.}
65\end{seealso}