]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91219: Add an index_pages default list and parameter to SimpleHTTPRequestHandler...
authorMyron Walker <myron.walker@hotmail.com>
Thu, 23 Jun 2022 20:30:44 +0000 (16:30 -0400)
committerGitHub <noreply@github.com>
Thu, 23 Jun 2022 20:30:44 +0000 (13:30 -0700)
* 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.

Lib/http/server.py
Misc/NEWS.d/next/Library/2022-03-19-04-41-42.bpo-47063.nwRfUo.rst [new file with mode: 0644]

index f2aeb65942020aeca4a3b3aa556beca52c5ad3d1..8aee31bac2752a7c3aeb5e225fb55f0b46bd97f6 100644 (file)
@@ -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
diff --git a/Misc/NEWS.d/next/Library/2022-03-19-04-41-42.bpo-47063.nwRfUo.rst b/Misc/NEWS.d/next/Library/2022-03-19-04-41-42.bpo-47063.nwRfUo.rst
new file mode 100644 (file)
index 0000000..b889d3c
--- /dev/null
@@ -0,0 +1 @@
+Add an index_pages parameter to support using non-default index page names.