This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add configurable DirectoryIndex to http.server
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, epaulson
Priority: normal Keywords: patch

Created on 2018-01-23 04:16 by epaulson, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 5308 open epaulson, 2018-01-25 04:19
Messages (3)
msg310468 - (view) Author: Erik Paulson (epaulson) * Date: 2018-01-23 04:16
In http.server and SimpleHTTPRequestHandler - the send_head function is hard-coded to treat index.html and index.htm as files to return in a directory - if neither of those files are present, it lists the directory. 

It would be very nice to be able to specify other files to use as a directory index, similar to the DirectoryIndex directive from Apache.

I think it'd be straight forward to add some kind of list you could set, just like you can modify extensions_map to include other types of MIME types. 

Would it be OK to just add a directory_index list with index.html and index.htm on by default that people could do like
Handler.directory_index.append("index.htmlx") in their setup? Or would such an API be better with some kind of helper?
msg344129 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2019-05-31 21:38
Thank you for the report and for the patch!

What's your use case? I understand the need for it for httpd, but as someone who uses http.server daily, I can't think of a use case that I'd find this feature useful. Note that even the example in your message and the test in the patch use artificial file names :)

Handler.directory_index.append("index.htmlx") API doesn't look good to me. It would be nice to subclass it, but that would make http.server less usable (especially if you run it via "python -m http.server")

I suggest closing this as 'rejected' (sorry!)
msg344137 - (view) Author: Erik Paulson (epaulson) * Date: 2019-05-31 22:47
I think my use case was Sharepoint and static site generators - Sharepoint can serve a tree of .aspx files as raw HTML, but maddeningly not .html files. The site generator we used spit out a fairly complicated site where the internal links point at directories counting on the fact that it is served correctly by the directoryindex handler. The site generator spits out .aspx but http.server can't serve them. 

A directory full of .xhtml files would have similar problems, which certainly still exist in the wild. 

The example in the test was named index.test because it's creating files on the disk in the test, shared by other parts of the test, and I wanted to be clear about what it was. It was not intended to be an example use case.
History
Date User Action Args
2022-04-11 14:58:56adminsetgithub: 76809
2019-05-31 22:47:17epaulsonsetmessages: + msg344137
2019-05-31 21:38:14berker.peksagsetnosy: + berker.peksag
messages: + msg344129
2018-01-25 04:19:15epaulsonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request5155
2018-01-23 04:16:45epaulsoncreate