Bug #1627575: Added _open() method to FileHandler which can be used to reopen files...
[python.git] / Doc / lib / libcgihttp.tex
blobdf0728e3f182a5172de338eee713d965cfa8a1f8
1 \section{\module{CGIHTTPServer} ---
2 CGI-capable HTTP request handler}
5 \declaremodule{standard}{CGIHTTPServer}
6 \sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
7 \modulesynopsis{This module provides a request handler for HTTP servers
8 which can run CGI scripts.}
11 The \module{CGIHTTPServer} module defines a request-handler class,
12 interface compatible with
13 \class{BaseHTTPServer.BaseHTTPRequestHandler} and inherits behavior
14 from \class{SimpleHTTPServer.SimpleHTTPRequestHandler} but can also
15 run CGI scripts.
17 \note{This module can run CGI scripts on \UNIX{} and Windows systems;
18 on Mac OS it will only be able to run Python scripts within the same
19 process as itself.}
21 \note{CGI scripts run by the \class{CGIHTTPRequestHandler} class cannot execute
22 redirects (HTTP code 302), because code 200 (script output follows)
23 is sent prior to execution of the CGI script. This pre-empts the status
24 code.}
26 The \module{CGIHTTPServer} module defines the following class:
28 \begin{classdesc}{CGIHTTPRequestHandler}{request, client_address, server}
29 This class is used to serve either files or output of CGI scripts from
30 the current directory and below. Note that mapping HTTP hierarchic
31 structure to local directory structure is exactly as in
32 \class{SimpleHTTPServer.SimpleHTTPRequestHandler}.
34 The class will however, run the CGI script, instead of serving it as a
35 file, if it guesses it to be a CGI script. Only directory-based CGI
36 are used --- the other common server configuration is to treat special
37 extensions as denoting CGI scripts.
39 The \function{do_GET()} and \function{do_HEAD()} functions are
40 modified to run CGI scripts and serve the output, instead of serving
41 files, if the request leads to somewhere below the
42 \code{cgi_directories} path.
43 \end{classdesc}
45 The \class{CGIHTTPRequestHandler} defines the following data member:
47 \begin{memberdesc}{cgi_directories}
48 This defaults to \code{['/cgi-bin', '/htbin']} and describes
49 directories to treat as containing CGI scripts.
50 \end{memberdesc}
52 The \class{CGIHTTPRequestHandler} defines the following methods:
54 \begin{methoddesc}{do_POST}{}
55 This method serves the \code{'POST'} request type, only allowed for
56 CGI scripts. Error 501, "Can only POST to CGI scripts", is output
57 when trying to POST to a non-CGI url.
58 \end{methoddesc}
60 Note that CGI scripts will be run with UID of user nobody, for security
61 reasons. Problems with the CGI script will be translated to error 403.
63 For example usage, see the implementation of the \function{test()}
64 function.
67 \begin{seealso}
68 \seemodule{BaseHTTPServer}{Base class implementation for Web server
69 and request handler.}
70 \end{seealso}