Reputation: 2089
If I mount a static directory in CherryPy, like so:
wwwroot_config = { '/':
{ 'tools.staticdir.on': True,
'tools.staticdir.dir': '/path/to/dir' } }
cherrypy.tree.mount(root, '/', config = wwwroot_config)
File downloads from that directory go pretty slowly.
However, if I create my own WSGI app...
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 speeds that are 4-5x faster.
However, this way is not as flexible because the headers that serve_file adds to the request (such as the range headers and content length) don't get returned in the response - I have to do it myself.
Is there anything I can do to make the first way faster?
Upvotes: 4
Views: 1187
Reputation: 300
I've had this same problem before, though only on Windows machines as I can recall. Are you running CherryPy on Windows? There seems to be a bug in CherryPy 3.5.0 which returns the wrong Content-Length header for static files, which causes the browser to sit idly waiting for more bytes which don't exist.
I haven't researched the issue in detail, but you might want to inspect the Content-Length header sent by the server, and see if it matches the actual size of the static files. A temporary workaround may be to manually set (or remove) the Content-Length header in a 'before_handler' hook.
Upvotes: 2