1 \section{\module{SimpleHTTPServer
} ---
2 A Do-Something Request Handler
}
4 \declaremodule{standard
}{SimpleHTTPServer
}
5 \sectionauthor{Moshe Zadka
}{mzadka@geocities.com
}
6 \modulesynopsis{This module provides a request handler for HTTP servers.
}
9 The
\module{SimpleHTTPServer
} module defines a request-handler class,
10 interface compatible with
\class{BaseHTTPServer.BaseHTTPRequestHandler
}
11 which serves files only from a base directory.
13 The
\module{SimpleHTTPServer
} module defines the following class:
15 \begin{classdesc
}{SimpleHTTPRequestHandler
}{request, client_address, server
}
16 This class is used, to serve files from current directory and below,
17 directly mapping the directory structure to HTTP requests.
19 A lot of the work is done by the base class
20 \class{BaseHTTPServer.BaseHTTPRequestHandler
}, such as parsing the
21 request. This class implements the
\function{do_GET()
} and
22 \function{do_HEAD()
} functions.
25 The
\class{SimpleHTTPRequestHandler
} defines the following member
28 \begin{memberdesc
}{server_version
}
29 This will be
\code{"SimpleHTTP/" + __version__
}, where
\code{__version__
}
30 is defined in the module.
33 \begin{memberdesc
}{extensions_map
}
34 A dictionary mapping suffixes into MIME types. Default is signified
35 by an empty string, and is considered to be
\code{text/plain
}.
36 The mapping is used case-insensitively, and so should contain only
40 The
\class{SimpleHTTPRequestHandler
} defines the following methods:
42 \begin{methoddesc
}{do_HEAD
}{}
43 This method serves the
\code{'HEAD'
} request type: it sends the
44 headers it would send for the equivalent
\code{GET
} request. See the
45 \method{do_GET()
} method for more complete explanation of the possible
49 \begin{methoddesc
}{do_GET
}{}
50 The request is mapped to a local file by interpreting the request as
51 a path relative to the current working directory.
53 If the request was mapped to a directory, a
\code{403} respond is output,
54 followed by the explanation
\code{'Directory listing not supported'
}.
55 Any
\exception{IOError
} exception in opening the requested file, is mapped
56 to a
\code{404},
\code{'File not found'
} error. Otherwise, the content
57 type is guessed using the
\var{extensions_map
} variable.
59 A
\code{'Content-type:'
} with the guessed content type is output, and
60 then a blank line, signifying end of headers, and then the contents of
61 the file. The file is always opened in binary mode.
63 For example usage, see the implementation of the
\function{test()
}
69 \seemodule{BaseHTTPServer
}{Base class implementation for Web server