Fixed: #2914 (RFE for UTC support in TimedRotatingFileHandler) and #2929 (wrong filen...
[python.git] / Doc / library / cgihttpserver.rst
blob6275c1a4d18a7fb6450aa7d75f25b022ea05c1a4
2 :mod:`CGIHTTPServer` --- CGI-capable HTTP request handler
3 =========================================================
5 .. module:: CGIHTTPServer
6    :synopsis: This module provides a request handler for HTTP servers which can run CGI
7               scripts.
8 .. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
11 The :mod:`CGIHTTPServer` module defines a request-handler class, interface
12 compatible with :class:`BaseHTTPServer.BaseHTTPRequestHandler` and inherits
13 behavior from :class:`SimpleHTTPServer.SimpleHTTPRequestHandler` but can also
14 run CGI scripts.
16 .. note::
18    This module can run CGI scripts on Unix and Windows systems; on Mac OS it will
19    only be able to run Python scripts within the same process as itself.
21 .. note::
23    CGI scripts run by the :class:`CGIHTTPRequestHandler` class cannot execute
24    redirects (HTTP code 302), because code 200 (script output follows) is sent
25    prior to execution of the CGI script.  This pre-empts the status code.
27 The :mod:`CGIHTTPServer` module defines the following class:
30 .. class:: CGIHTTPRequestHandler(request, client_address, server)
32    This class is used to serve either files or output of CGI scripts from  the
33    current directory and below. Note that mapping HTTP hierarchic structure to
34    local directory structure is exactly as in
35    :class:`SimpleHTTPServer.SimpleHTTPRequestHandler`.
37    The class will however, run the CGI script, instead of serving it as a file, if
38    it guesses it to be a CGI script. Only directory-based CGI are used --- the
39    other common server configuration is to treat special extensions as denoting CGI
40    scripts.
42    The :func:`do_GET` and :func:`do_HEAD` functions are modified to run CGI scripts
43    and serve the output, instead of serving files, if the request leads to
44    somewhere below the ``cgi_directories`` path.
46    The :class:`CGIHTTPRequestHandler` defines the following data member:
49    .. attribute:: cgi_directories
51       This defaults to ``['/cgi-bin', '/htbin']`` and describes directories to
52       treat as containing CGI scripts.
54    The :class:`CGIHTTPRequestHandler` defines the following methods:
57    .. method:: do_POST()
59       This method serves the ``'POST'`` request type, only allowed for CGI
60       scripts.  Error 501, "Can only POST to CGI scripts", is output when trying
61       to POST to a non-CGI url.
63 Note that CGI scripts will be run with UID of user nobody, for security reasons.
64 Problems with the CGI script will be translated to error 403.
66 For example usage, see the implementation of the :func:`test` function.
69 .. seealso::
71    Module :mod:`BaseHTTPServer`
72       Base class implementation for Web server and request handler.