summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/library/http.server.rst5
-rw-r--r--Lib/http/server.py6
-rw-r--r--Misc/NEWS.d/next/Library/2023-01-03-11-06-28.gh-issue-91219.s5IFCw.rst2
3 files changed, 9 insertions, 4 deletions
diff --git a/Doc/library/http.server.rst b/Doc/library/http.server.rst
index 3290b9b..ae75e6d 100644
--- a/Doc/library/http.server.rst
+++ b/Doc/library/http.server.rst
@@ -413,6 +413,11 @@ the current directory::
print("serving at port", PORT)
httpd.serve_forever()
+
+:class:`SimpleHTTPRequestHandler` can also be subclassed to enhance behavior,
+such as using different index file names by overriding the class attribute
+:attr:`index_pages`.
+
.. _http-server-cli:
:mod:`http.server` can also be invoked directly using the :option:`-m`
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 221c8be..971f080 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -652,8 +652,8 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
"""
- index_pages = ["index.html", "index.htm"]
server_version = "SimpleHTTP/" + __version__
+ index_pages = ("index.html", "index.htm")
extensions_map = _encodings_map_default = {
'.gz': 'application/gzip',
'.Z': 'application/octet-stream',
@@ -661,11 +661,9 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
'.xz': 'application/x-xz',
}
- def __init__(self, *args, directory=None, index_pages=None, **kwargs):
+ def __init__(self, *args, directory=None, **kwargs):
if directory is None:
directory = os.getcwd()
- if index_pages is not None:
- self.index_pages = index_pages
self.directory = os.fspath(directory)
super().__init__(*args, **kwargs)
diff --git a/Misc/NEWS.d/next/Library/2023-01-03-11-06-28.gh-issue-91219.s5IFCw.rst b/Misc/NEWS.d/next/Library/2023-01-03-11-06-28.gh-issue-91219.s5IFCw.rst
new file mode 100644
index 0000000..cb5e2e4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-01-03-11-06-28.gh-issue-91219.s5IFCw.rst
@@ -0,0 +1,2 @@
+Change ``SimpleHTTPRequestHandler`` to support subclassing to provide a
+different set of index file names instead of using ``__init__`` parameters.