Skip to content

Commit ecbf136

Browse files
[3.10] gh-100474: Fix handling of dirs named index.html in http.server (GH-100504)
Co-authored-by: James Frost <git@frost.cx>
1 parent 0dea924 commit ecbf136

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Lib/http/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def send_head(self):
709709
return None
710710
for index in "index.html", "index.htm":
711711
index = os.path.join(path, index)
712-
if os.path.exists(index):
712+
if os.path.isfile(index):
713713
path = index
714714
break
715715
else:

Lib/test/test_httpservers.py

+3
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ def test_get(self):
488488
self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)
489489
response = self.request('/' + 'ThisDoesNotExist' + '/')
490490
self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)
491+
os.makedirs(os.path.join(self.tempdir, 'spam', 'index.html'))
492+
response = self.request(self.base_url + '/spam/')
493+
self.check_status_and_reason(response, HTTPStatus.OK)
491494

492495
data = b"Dummy index file\r\n"
493496
with open(os.path.join(self.tempdir_name, 'index.html'), 'wb') as f:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`http.server` now checks that an index page is actually a regular file before trying
2+
to serve it. This avoids issues with directories named ``index.html``.

0 commit comments

Comments
 (0)