annotate Doc/lib/libcgihttp.tex @ 10982:bef46ea5ef75 legacy-trunk

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