Skip to content

Commit 1f191e4

Browse files
committed
- Implemented request #44164, zlib.output_compression is now implicitly
disabled when the header "Content-length" is set. #One could argue that any output handler could change the size of the #response, so this exception for zlib.output_compression is an #inconsistency. However, zlib.output_compression is presented as a #performance setting, whose value should have no effect on the #correctness of the scripts. This was not the case. Setting the #header "content-length" and enabling zlib.output_compression was #a recipe for infringing section 4.4 of RFC 2616.
1 parent 18fa045 commit 1f191e4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

main/SAPI.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,14 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
706706
}
707707
efree(mimetype);
708708
SG(sapi_headers).send_default_content_type = 0;
709+
} else if (!STRCASECMP(header_line, "Content-Length")) {
710+
/* Script is setting Content-length. The script cannot reasonably
711+
* know the size of the message body after compression, so it's best
712+
* do disable compression altogether. This contributes to making scripts
713+
* portable between setups that have and don't have zlib compression
714+
* enabled globally. See req #44164 */
715+
zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"),
716+
"0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
709717
} else if (!STRCASECMP(header_line, "Location")) {
710718
if ((SG(sapi_headers).http_response_code < 300 ||
711719
SG(sapi_headers).http_response_code > 307) &&

tests/basic/req44164.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Req #44164 (Handle "Content-Length" HTTP header when zlib.output_compression active)
3+
--SKIPIF--
4+
<?php
5+
if (!function_exists('gzdeflate'))
6+
die("skip zlib extension required");
7+
?>
8+
--INI--
9+
zlib.output_compression=On
10+
--ENV--
11+
HTTP_ACCEPT_ENCODING=gzip
12+
--FILE--
13+
<?php
14+
header("Content-length: 200");
15+
echo str_repeat("a", 200);
16+
--EXPECT--
17+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

0 commit comments

Comments
 (0)