@@ -39,7 +39,17 @@ handler. Code to create and run the server looks like this::
3939 This class builds on the :class: `~socketserver.TCPServer ` class by storing
4040 the server address as instance variables named :attr: `server_name ` and
4141 :attr: `server_port `. The server is accessible by the handler, typically
42- through the handler's :attr: `server ` instance variable.
42+ through the handler's :attr: `~socketserver.BaseRequestHandler.server `
43+ instance variable.
44+
45+ .. attribute :: server_name
46+
47+ The HTTP server's fully qualified domain name.
48+
49+ .. attribute :: server_port
50+
51+ The HTTP server's port number obtained from *server_address *.
52+
4353
4454.. class :: ThreadingHTTPServer(server_address, RequestHandlerClass)
4555
@@ -390,6 +400,14 @@ instantiation, of which this module provides three different variants:
390400 This will be ``"SimpleHTTP/" + __version__ ``, where ``__version__ `` is
391401 defined at the module level.
392402
403+ .. attribute :: index_pages
404+
405+ Specifies the filenames that are treated as directory index pages.
406+
407+ Defaults to ``("index.html", "index.htm") ``.
408+
409+ .. versionadded :: 3.12
410+
393411 .. attribute :: extensions_map
394412
395413 A dictionary mapping suffixes into MIME types, contains custom overrides
@@ -414,7 +432,7 @@ instantiation, of which this module provides three different variants:
414432 path relative to the current working directory.
415433
416434 If the request was mapped to a directory, the directory is checked for a
417- file named `` index.html `` or `` index.htm `` (in that order) . If found, the
435+ an index page as specified by :attr: ` index_pages ` . If found, the
418436 file's contents are returned; otherwise a directory listing is generated
419437 by calling the :meth: `list_directory ` method. This method uses
420438 :func: `os.listdir ` to scan the directory, and returns a ``404 `` error
@@ -441,6 +459,30 @@ instantiation, of which this module provides three different variants:
441459 .. versionchanged :: 3.7
442460 Support of the ``'If-Modified-Since' `` header.
443461
462+ .. method :: list_directory(path)
463+
464+ Helper to list the contents of *path * when no index page is present.
465+
466+ This returns either a :term: `file-like object ` (which must be closed
467+ by the caller) or ``None `` to indicate an error, in which case the
468+ caller has nothing further to do. In either case, the headers are sent.
469+
470+ .. method :: guess_type(path)
471+
472+ Guess the type of the file at the given *path *.
473+
474+ This returns a string of the form ``type/subtype ``, usable for
475+ a MIME Content-type header.
476+
477+ The default implementation looks the file's extension up in
478+ :attr: `extensions_map `, falling back to
479+ :func: `mimetypes.guess_file_type ` and then to
480+ ``'application/octet-stream' ``.
481+
482+ .. versionchanged :: 3.13
483+ Add :func: `mimetypes.guess_file_type ` as a fallback.
484+
485+
444486The :class: `SimpleHTTPRequestHandler ` class can be used in the following
445487manner in order to create a very basic webserver serving files relative to
446488the current directory::
@@ -459,7 +501,7 @@ the current directory::
459501
460502:class: `SimpleHTTPRequestHandler ` can also be subclassed to enhance behavior,
461503such as using different index file names by overriding the class attribute
462- :attr: `index_pages `.
504+ :attr: `~SimpleHTTPRequestHandler. index_pages `.
463505
464506
465507.. class :: CGIHTTPRequestHandler(request, client_address, server)
0 commit comments