Question

I'm still struggling to Stream a file to the HTTP response in Pylons. In addition to the original problem, I'm finding that I cannot return the Content-Length header, so that for large files the client cannot estimate how long the download will take. I've tried

response.content_length = 12345

and I've tried

response.headers['Content-Length'] = 12345

In both cases the HTTP response (viewed in Fiddler) simply does not contain the Content-Length header. How do I get Pylons to return this header?

(Oh, and if you have any ideas on making it stream the file please reply to the original question - I'm all out of ideas there.)

Edit: while not a generic solution, for serving static files FileApp allows sending the Content-Length header. For dynamic content it looks like Alex Martelli's answer is the only option.

Was it helpful?

Solution

There's a bit of middleware code here that ensures all responses get a content length header if they're missing it. You could tweak it so that you set some other header in your response (say 'X-The-Content-Length') and the middleware uses that to make the content length if the latter's missing. I view the whole thing as a workaround for what I consider a pylons bug (its cavalier attitude to content length!) but apparently the pylons authors disagree with me on that score, so it's nice to at least have workarounds for it!-)

OTHER TIPS

Try:

response.headerlist.append((str("Content-Length"), str(" 123456")))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top