开发者

HTTP Content-Length header has 1 byte too many

开发者 https://www.devze.com 2023-03-02 16:58 出处:网络
I\'m writing a (PHP) script that serves files to the client. Among others, the Content-Length header is sent, only it has one byte too many. I discovered this when I put the content length in a differ

I'm writing a (PHP) script that serves files to the client. Among others, the Content-Length header is sent, only it has one byte too many. I discovered this when I put the content length in a different header, and compared the two:

$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. I suspect Apache doing this to my headers.

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. When I try this code outside of ZF, all is well. Maybe ZF is doing output buffering, and re-sending the headers itself or something, but I don't really know ZF that well.


This was not Apache's doing, but a space before a PHP open tag in combination with output buffering.

0

精彩评论

暂无评论...
验证码 换一张
取 消