Content-Length header not returned from Pylons response

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

response.content_length = 12345 

and i tried

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

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

(Oh, and if you have any ideas on how it will transfer the file, answer the original question - I have all the ideas here.)

Edit: While not a general solution, FileApp allows you to send a Content-Length header to serve static files. For dynamic content, it looks like Alex Martelli's Answer is the only option.

+2
python content-length pylons
source share
2 answers

There's a bit of intermediate code here , which ensures that all responses get a content length header if they are missing. You can configure it so that a different header is added in your response (for example, "X-The-Content-Length"), and the middleware uses this to make the length of the content if the latter is missing. I consider all this as a workaround for what I consider to be a pylon error (its cavalry attitude to the length of the content!), But, apparently, the authors of the pylons do not agree with me on this score, so it’s nice to have at least workarounds for this ! -)

+1
source share

Try:

 response.headerlist.append((str("Content-Length"), str(" 123456"))) 
0
source share

All Articles