diff --git a/ext/zlib/tests/bug44168.phpt b/ext/zlib/tests/bug44168.phpt new file mode 100644 index 0000000000000..2438caafb809a Binary files /dev/null and b/ext/zlib/tests/bug44168.phpt differ diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 1a202e344ed43..7cb4ff54812a1 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -205,10 +205,14 @@ static int php_zlib_output_handler(void **handler_context, php_output_context *o if (SUCCESS == php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS, &flags TSRMLS_CC)) { /* only run this once */ if (!(flags & PHP_OUTPUT_HANDLER_STARTED)) { + sapi_header_line cl_header = {ZEND_STRL("Content-Length"), 0}; + if (SG(headers_sent) || !ZLIBG(output_compression)) { deflateEnd(&ctx->Z); return FAILURE; } + + sapi_header_op(SAPI_HEADER_DELETE, &cl_header); switch (ZLIBG(compression_coding)) { case PHP_ZLIB_ENCODING_GZIP: sapi_add_header_ex(ZEND_STRL("Content-Encoding: gzip"), 1, 1 TSRMLS_CC); diff --git a/main/SAPI.c b/main/SAPI.c index dcb2da629a03b..c737f5ec7cd6e 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -804,14 +804,6 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) } efree(mimetype); SG(sapi_headers).send_default_content_type = 0; - } else if (!STRCASECMP(header_line, "Content-Length")) { - /* Script is setting Content-length. The script cannot reasonably - * know the size of the message body after compression, so it's best - * do disable compression altogether. This contributes to making scripts - * portable between setups that have and don't have zlib compression - * enabled globally. See req #44164 */ - zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), - "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); } else if (!STRCASECMP(header_line, "Location")) { if ((SG(sapi_headers).http_response_code < 300 || SG(sapi_headers).http_response_code > 307) &&