简体   繁体   English

HTTP 内容长度 header 1 字节过多

[英]HTTP Content-Length header has 1 byte too many

I'm writing a (PHP) script that serves files to the client.我正在编写一个(PHP)脚本,为客户端提供文件。 Among others, the Content-Length header is sent, only it has one byte too many.其中,Content-Length header 被发送,只是它有一个字节太多。 I discovered this when I put the content length in a different header, and compared the two:当我将内容长度放在不同的 header 中时,我发现了这一点,并比较了两者:

$filesize = filesize($file);
header('Content-Length: ' . $filesize);
header('X-Content-Length: ' . $filesize);

Result:结果:

Content-Length: 3481
X-Content-Length: 3480

Even when hard-coding 3480 into the header() function, this is the outcome.即使将3480硬编码到header() function 中,结果也是如此。 I suspect Apache doing this to my headers.我怀疑 Apache 对我的标题这样做。

What might be causing this?这可能是什么原因造成的?

Edit: To give some context: I think Zend Framework is causing this: I'm refactoring code that is currently in production (and working) to ZF, where the problem occurs.编辑:给出一些上下文:我认为 Zend Framework 导致了这个:我正在将当前正在生产(和工作)的代码重构到出现问题的 ZF。 When I try this code outside of ZF, all is well.当我在 ZF 之外尝试这段代码时,一切都很好。 Maybe ZF is doing output buffering, and re-sending the headers itself or something, but I don't really know ZF that well.也许 ZF 正在做 output 缓冲,并重新发送标头本身或其他东西,但我不太了解 ZF。

This was not Apache's doing, but a space before a PHP open tag in combination with output buffering.这不是 Apache 做的,而是 PHP 开放标记与 output 缓冲组合之前的一个空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM