I need to serve a binary file from disk, not
available in the normal folder for static content. In my code so far I've done
something like this in the render-method :
request.setContentType( .... content-type set based
on extension of file to serve )
f = open(somefile)
while 1:
d = f.read(2048) # what's the
correct size to read
if not d:
break
request.write(d)
request.finish()
return
It seem to return the data OK, it's visible in the
browser, but exceptions are raised in the server. How do I close this connection
the right way? Should this be used with deferred or something like that? The
files can be huge in size.
PS! From recent postings in this list is seems as
if Twisted doesn't support compression of content, using gzip etc. Is this true?
This would speed up things considerably. I implemented this in my previous
webserver-project using BaseHTTPServer and on big files the increase in speed
was impressive. Compressing HTML/Plain text/XML etc., just files known to be
based in plain text, would be a great start.
Best regards,
Thomas Weholt