Apparently the code to forestall Tk eating events was too aggressive (Tk user input...
[python/dscho.git] / Doc / lib / libsimplehttp.tex
blob67452985a7b4fd94ae66e6fb761bb5fbbd1cd679
1 \section{\module{SimpleHTTPServer} ---
2 Simple HTTP request handler}
4 \declaremodule{standard}{SimpleHTTPServer}
5 \sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
6 \modulesynopsis{This module provides a basic request handler for HTTP
7 servers.}
10 The \module{SimpleHTTPServer} module defines a request-handler class,
11 interface compatible with \class{BaseHTTPServer.BaseHTTPRequestHandler}
12 which serves files only from a base directory.
14 The \module{SimpleHTTPServer} module defines the following class:
16 \begin{classdesc}{SimpleHTTPRequestHandler}{request, client_address, server}
17 This class is used, to serve files from current directory and below,
18 directly mapping the directory structure to HTTP requests.
20 A lot of the work is done by the base class
21 \class{BaseHTTPServer.BaseHTTPRequestHandler}, such as parsing the
22 request. This class implements the \function{do_GET()} and
23 \function{do_HEAD()} functions.
24 \end{classdesc}
26 The \class{SimpleHTTPRequestHandler} defines the following member
27 variables:
29 \begin{memberdesc}{server_version}
30 This will be \code{"SimpleHTTP/" + __version__}, where \code{__version__}
31 is defined in the module.
32 \end{memberdesc}
34 \begin{memberdesc}{extensions_map}
35 A dictionary mapping suffixes into MIME types. Default is signified
36 by an empty string, and is considered to be \code{text/plain}.
37 The mapping is used case-insensitively, and so should contain only
38 lower-cased keys.
39 \end{memberdesc}
41 The \class{SimpleHTTPRequestHandler} defines the following methods:
43 \begin{methoddesc}{do_HEAD}{}
44 This method serves the \code{'HEAD'} request type: it sends the
45 headers it would send for the equivalent \code{GET} request. See the
46 \method{do_GET()} method for more complete explanation of the possible
47 headers.
48 \end{methoddesc}
50 \begin{methoddesc}{do_GET}{}
51 The request is mapped to a local file by interpreting the request as
52 a path relative to the current working directory.
54 If the request was mapped to a directory, a \code{403} respond is output,
55 followed by the explanation \code{'Directory listing not supported'}.
56 Any \exception{IOError} exception in opening the requested file, is mapped
57 to a \code{404}, \code{'File not found'} error. Otherwise, the content
58 type is guessed using the \var{extensions_map} variable.
60 A \code{'Content-type:'} with the guessed content type is output, and
61 then a blank line, signifying end of headers, and then the contents of
62 the file. The file is always opened in binary mode.
64 For example usage, see the implementation of the \function{test()}
65 function.
66 \end{methoddesc}
69 \begin{seealso}
70 \seemodule{BaseHTTPServer}{Base class implementation for Web server
71 and request handler.}
72 \end{seealso}