简体   繁体   中英

HTTP Content-Length header has 1 byte too many

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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