2

I am serving a local directory with Twisted http server as:

from twisted.web.server import Site
from twisted.web.static import File
from twisted.internet import reactor, endpoints

resource = File('./')
factory = Site(resource)
reactor.listenTCP(8888,factory)
reactor.run()

The server serves the specified directory properly. But, when there is any index file (index, index.html) in a directory, then the server displays that index file, instead of serving the local directory. So, how do I tell Twisted server to ignore the index files and continue to serve the local directory?

pro neon
  • 253
  • 1
  • 12

1 Answers1

2

twisted.web.static.File uses self.indexNames to determine which files are considered index files. You can override this value to change the behavior.

from twisted.web.server import Site
from twisted.web.static import File
from twisted.internet import reactor, endpoints

resource = File('./')
resource.indexNames = []
factory = Site(resource)
reactor.listenTCP(8888,factory)
reactor.run()
Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122