pro neon
pro neon

Reputation: 253

How to tell Twisted http server to ignore index files

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?

Upvotes: 2

Views: 82

Answers (1)

Jean-Paul Calderone
Jean-Paul Calderone

Reputation: 48335

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

Upvotes: 2

Related Questions