If I mount the static directory in CherryPy, like this:
wwwroot_config = { '/': { 'tools.staticdir.on': True, 'tools.staticdir.dir': '/path/to/dir' } } cherrypy.tree.mount(root, '/', config = wwwroot_config)
Downloading files from this directory is rather slow.
However, if I create my own WSGI application ...
self.wsgi_server = wsgiserver.CherryPyWSGIServer((self.bindaddress, self.port), self.download_file, numthreads = 1)
With self.download_file containing basically:
return serve_file(theFile, "application/x-download", "attachment", os.path.basename(theFile), debug = True)
I get a speed that is 4-5 times faster.
However, this method is not so flexible because the headers that serve_file adds to the request (for example, range headers and content lengths) do not return in response - I have to do it myself.
Is there something I can do to make the first way faster?
source share