@@ -33,7 +33,7 @@ \section{\module{SimpleHTTPServer} ---
3333
3434\begin {memberdesc }{extensions_map}
3535A dictionary mapping suffixes into MIME types. Default is signified
36- by an empty string, and is considered to be \code {text/plain }.
36+ by an empty string, and is considered to be \code {application/octet-stream }.
3737The mapping is used case-insensitively, and so should contain only
3838lower-cased keys.
3939\end {memberdesc }
@@ -51,15 +51,23 @@ \section{\module{SimpleHTTPServer} ---
5151The request is mapped to a local file by interpreting the request as
5252a path relative to the current working directory.
5353
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.
54+ If the request was mapped to a directory, the directory is checked for
55+ a file named \code {index.html} or \code {index.htm} (in that order).
56+ If found, the file's contents are returned; otherwise a directory
57+ listing is generated by calling the \method {list_directory()} method.
58+ This method uses \function {os.listdir()} to scan the directory, and
59+ returns a \code {404} error response if the \function {listdir()} fails.
60+
61+ If the request was mapped to a file, it is opened and the contents are
62+ returned. Any \exception {IOError} exception in opening the requested
63+ file is mapped to a \code {404}, \code {'File not found'}
64+ error. Otherwise, the content type is guessed using the
65+ \var {extensions_map} variable.
5966
6067A \code {'Content-type:'} with the guessed content type is output, and
6168then a blank line, signifying end of headers, and then the contents of
62- the file. The file is always opened in binary mode.
69+ the file. If the file's MIME type starts with \code {text/} the file is
70+ opened in text mode; otherwise binary mode is used.
6371
6472For example usage, see the implementation of the \function {test()}
6573function.
0 commit comments