ID: 44164 User updated by: mplomer at gmx dot de -Summary: Clear "Content-Length" HTTP header when zlib.output_compression active Reported By: mplomer at gmx dot de Status: Open Bug Type: Zlib Related Operating System: any PHP Version: 5.2.5 New Comment:
Another idea is: IF the Content-Length header IS set from the script, THEN buffer the complete output and calculate the correct compressed Content-Length. ELSE do nothing (do not add any Content-Length header) So ob_flush(), flush() will still work if compression is active. (Which will not work, if we use apache's mod_deflate. This is why "zlib.output_compression" is required.) Previous Comments: ------------------------------------------------------------------------ [2008-02-19 10:48:09] mplomer at gmx dot de Description: ------------ If you have a big project, where "Content-Length" header is set on many places, and then you turn on "zlib.output_compression", you will have a problem, because the original header is still passed through, but it is invalid now, because it contains the length of the uncompressed data instead of the compressed data. This would confuse some HTTP clients, that rely on the "Content-Length". I think, "zlib.output_compression" should be completely transparent, so this issue should be handled in php core. One solution is, to remove the "Content-Length" header (if set) in ob_gzhandler() in ext/zlib/zlib.c:882 (where "Content-Encoding: gzip" header is set). If you see a good way to set the Content-Length to the compressed length, this would be, of course, the best solution, but this is IMHO only possible, if the entire data is buffered before (or is this done by ob_gzhandler anyway?). This would make the various workarounds irrelevant that have to be done if "zlib.output_compression" is active and is completely backward compatible. Reproduce code: --------------- In php.ini: zlib.output_compression = On <?php $output = str_repeat('A', 8192); header('Content-Length: ' . strlen($output)); ?> Expected result: ---------------- Correct "Content-Length" header or removed "Content-Length" header in response, because the old length is always wrong. Better send no "Content-Length" instead a wrong length. Actual result: -------------- The old "Content-Length" header is sent. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44164&edit=1