summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorMyron Walker <myron.walker@hotmail.com>2022-06-23 20:30:44 (GMT)
committerGitHub <noreply@github.com>2022-06-23 20:30:44 (GMT)
commit9a95fa9267590c6cc66f215cd9808905fda1ee25 (patch)
tree624141552801a632836f4139642b855c353a4640 /Lib/http
parent4e796f56465f7264ddba63c8396d2649e098b617 (diff)
downloadcpython-9a95fa9267590c6cc66f215cd9808905fda1ee25.zip
cpython-9a95fa9267590c6cc66f215cd9808905fda1ee25.tar.gz
cpython-9a95fa9267590c6cc66f215cd9808905fda1ee25.tar.bz2
gh-91219: Add an index_pages default list and parameter to SimpleHTTPRequestHandler (GH-31985)
* Add an index_pages default list to SimpleHTTPRequestHandler and an optional constructor parameter that allows the default indexes pages list to be overridden. This makes it easy to set a new index page name without having to override send_head.
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/server.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index f2aeb65..8aee31b 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -642,6 +642,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
"""
+ index_pages = ["index.html", "index.htm"]
server_version = "SimpleHTTP/" + __version__
extensions_map = _encodings_map_default = {
'.gz': 'application/gzip',
@@ -650,9 +651,11 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
'.xz': 'application/x-xz',
}
- def __init__(self, *args, directory=None, **kwargs):
+ def __init__(self, *args, directory=None, index_pages=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)
@@ -696,7 +699,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
self.send_header("Content-Length", "0")
self.end_headers()
return None
- for index in "index.html", "index.htm":
+ for index in self.index_pages:
index = os.path.join(path, index)
if os.path.exists(index):
path = index