Edit report at http://bugs.php.net/bug.php?id=44164&edit=1

 ID:                 44164
 Comment by:         cataphr...@php.net
 Reported by:        mplomer at gmx dot de
 Summary:            Handle "Content-Length" HTTP header when
                     zlib.output_compression active
 Status:             Assigned
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   *
 PHP Version:        5.2.5
 Assigned To:        cataphract
 Block user comment: N

 New Comment:

I've just been hit by this problem and I'm thinking a better option
would be to disable zlib.output_compression if the Content-Length header
is set. What do you think?



Buffering everything and then calculating the actual length is not
really an option, the output could be several hundred megabytes.


Previous Comments:
------------------------------------------------------------------------
[2008-02-19 11:04:24] mplomer at gmx dot de

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

------------------------------------------------------------------------
[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/bug.php?id=44164&edit=1

Reply via email to