内容长度标头未从Pylons响应返回 [英] Content-Length header not returned from Pylons response

查看:150
本文介绍了内容长度标头未从Pylons响应返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然在努力将文件流式传输到Pylons中的HTTP响应。除了原始问题,我发现我无法返回Content-Length标头,因此对于大文件,客户端无法估计下载需要多长时间。我试过了

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

我已经尝试了

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

在这两种情况下,HTTP响应(在Fiddler中查看)根本不包含Content-长度标题。如何让Pylons返回此标题?

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.)

编辑,而不是通用的解决方案,用于提供静态文件 FileApp 允许发送内容 - 长度标题。对于动态内容,它看起来像 Alex Martelli 的答案是唯一的选择。

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.

推荐答案

有一个一点中间件代码这里确保所有如果他们错过了响应,则会获得内容长度标题。你可以调整它,以便在响应中设置一些其他标题(比如'X-The-Content-Length'),如果后者丢失,中间件会使用它来制作内容长度。我认为整个事情是我认为是一个塔架虫(它对内容长度的骑士态度!)的解决方法,但显然塔架作者在这个分数上不同意我的意见,所以至少有它的解决办法很好! - )

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!-)

这篇关于内容长度标头未从Pylons响应返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆