Skip to content

Add configurable DirectoryIndex to http.server #76809

Description

@epaulson
mannequin
BPO 32628
Nosy @berkerpeksag, @epaulson
PRs
  • gh-76809: support DirectoryIndex for http server #5308
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2018-01-23.04:16:45.000>
    labels = ['3.7', 'library']
    title = 'Add configurable DirectoryIndex to http.server'
    updated_at = <Date 2019-05-31.22:47:17.231>
    user = 'https://github.com/epaulson'

    bugs.python.org fields:

    activity = <Date 2019-05-31.22:47:17.231>
    actor = 'epaulson'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2018-01-23.04:16:45.000>
    creator = 'epaulson'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32628
    keywords = ['patch']
    message_count = 3.0
    messages = ['310468', '344129', '344137']
    nosy_count = 2.0
    nosy_names = ['berker.peksag', 'epaulson']
    pr_nums = ['5308']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue32628'
    versions = ['Python 3.7']

    Activity

    1. epaulson commented on Jan 23, 2018

      epaulsonmannequin
      MannequinAuthor

      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?

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Jan 23, 2018
    3. berkerpeksag commented on May 31, 2019

      @berkerpeksag
      Member

      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!)

    4. epaulson commented on May 31, 2019

      epaulsonmannequin
      MannequinAuthor

      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.

    5. transferred this issue fromon Apr 10, 2022
    6. soreavis commented on Jul 13, 2026

      @soreavis
      Contributor

      This looks resolved — index_pages was added to SimpleHTTPRequestHandler in 3.12 via gh-91219, and it's a documented class attribute you can override:

      class Handler(http.server.SimpleHTTPRequestHandler):
          index_pages = ("index.aspx",)

      That covers the .aspx and .xhtml cases from this thread. Worth closing this and #5308 as superseded?

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directory

      Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions