74
74
#endif
75
75
76
76
#define OS_CODE 0x03 /* FIXME */
77
- #define CODING_GZIP 1
78
- #define CODING_DEFLATE 2
79
77
#define GZIP_HEADER_LENGTH 10
80
78
#define GZIP_FOOTER_LENGTH 8
81
79
@@ -144,6 +142,26 @@ static PHP_INI_MH(OnUpdate_zlib_output_compression)
144
142
return FAILURE ;
145
143
}
146
144
145
+ if (new_value == NULL )
146
+ return FAILURE ;
147
+
148
+ if (!strncasecmp (new_value , "off" , sizeof ("off" ))) {
149
+ new_value = "0" ;
150
+ new_value_length = sizeof ("0" );
151
+ } else if (!strncasecmp (new_value , "on" , sizeof ("on" ))) {
152
+ new_value = "4096" ;
153
+ new_value_length = sizeof ("4096" );
154
+ } else if (stage == PHP_INI_STAGE_RUNTIME &&
155
+ strncmp (new_value , "0" , sizeof ("0" )) && strncmp (new_value , "1" , sizeof ("1" ))) {
156
+ php_error (E_WARNING , "Cannot change zlib.output_compression buffer size during script execution" );
157
+ return FAILURE ;
158
+ }
159
+
160
+ if (stage == PHP_INI_STAGE_RUNTIME && SG (headers_sent ) && !SG (request_info ).no_headers ) {
161
+ php_error (E_WARNING , "Cannot change zlib.output_compression - headers already sent" );
162
+ return FAILURE ;
163
+ }
164
+
147
165
OnUpdateInt (entry , new_value , new_value_length , mh_arg1 , mh_arg2 , mh_arg3 , stage TSRMLS_CC );
148
166
149
167
return SUCCESS ;
@@ -161,7 +179,7 @@ static PHP_INI_MH(OnUpdate_zlib_output_compression_level)
161
179
162
180
163
181
PHP_INI_BEGIN ()
164
- STD_PHP_INI_BOOLEAN ("zlib.output_compression" , "0" , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdate_zlib_output_compression , output_compression , zend_zlib_globals , zlib_globals )
182
+ STD_PHP_INI_BOOLEAN ("zlib.output_compression" , "0" , PHP_INI_ALL , OnUpdate_zlib_output_compression , output_compression , zend_zlib_globals , zlib_globals )
165
183
STD_PHP_INI_ENTRY ("zlib.output_compression_level" , "-1" , PHP_INI_ALL , OnUpdate_zlib_output_compression_level , output_compression_level , zend_zlib_globals , zlib_globals )
166
184
PHP_INI_END ()
167
185
@@ -197,6 +215,7 @@ PHP_MINIT_FUNCTION(zlib)
197
215
PHP_RINIT_FUNCTION (zlib )
198
216
{
199
217
ZLIBG (ob_gzhandler_status ) = 0 ;
218
+ ZLIBG (ob_gzip_coding ) = 0 ;
200
219
switch (ZLIBG (output_compression )) {
201
220
case 0 :
202
221
break ;
@@ -947,11 +966,15 @@ static void php_gzip_output_handler(char *output, uint output_len, char **handle
947
966
{
948
967
zend_bool do_start , do_end ;
949
968
950
- do_start = (mode & PHP_OUTPUT_HANDLER_START ? 1 : 0 );
951
- do_end = (mode & PHP_OUTPUT_HANDLER_END ? 1 : 0 );
952
- if (php_deflate_string (output , output_len , handled_output , handled_output_len , ZLIBG (ob_gzip_coding ), do_start , do_end , ZLIBG (output_compression_level ) TSRMLS_CC )!= SUCCESS ) {
953
- zend_error (E_ERROR , "Compression failed" );
954
- }
969
+ if (!ZLIBG (output_compression )) {
970
+ * handled_output = NULL ;
971
+ } else {
972
+ do_start = (mode & PHP_OUTPUT_HANDLER_START ? 1 : 0 );
973
+ do_end = (mode & PHP_OUTPUT_HANDLER_END ? 1 : 0 );
974
+ if (php_deflate_string (output , output_len , handled_output , handled_output_len , ZLIBG (ob_gzip_coding ), do_start , do_end , ZLIBG (output_compression_level ) TSRMLS_CC )!= SUCCESS ) {
975
+ zend_error (E_ERROR , "Compression failed" );
976
+ }
977
+ }
955
978
}
956
979
/* }}} */
957
980
@@ -968,20 +991,8 @@ int php_enable_output_compression(int buffer_size TSRMLS_DC)
968
991
}
969
992
convert_to_string_ex (a_encoding );
970
993
if (php_memnstr (Z_STRVAL_PP (a_encoding ), "gzip" , 4 , Z_STRVAL_PP (a_encoding ) + Z_STRLEN_PP (a_encoding ))) {
971
- if (sapi_add_header ("Content-Encoding: gzip" , sizeof ("Content-Encoding: gzip" ) - 1 , 1 )== FAILURE ) {
972
- return FAILURE ;
973
- }
974
- if (sapi_add_header ("Vary: Accept-Encoding" , sizeof ("Vary: Accept-Encoding" ) - 1 , 1 )== FAILURE ) {
975
- return FAILURE ;
976
- }
977
994
ZLIBG (ob_gzip_coding ) = CODING_GZIP ;
978
995
} else if (php_memnstr (Z_STRVAL_PP (a_encoding ), "deflate" , 7 , Z_STRVAL_PP (a_encoding ) + Z_STRLEN_PP (a_encoding ))) {
979
- if (sapi_add_header ("Content-Encoding: deflate" , sizeof ("Content-Encoding: deflate" ) - 1 , 1 )== FAILURE ) {
980
- return FAILURE ;
981
- }
982
- if (sapi_add_header ("Vary: Accept-Encoding" , sizeof ("Vary: Accept-Encoding" ) - 1 , 1 )== FAILURE ) {
983
- return FAILURE ;
984
- }
985
996
ZLIBG (ob_gzip_coding ) = CODING_DEFLATE ;
986
997
} else {
987
998
return FAILURE ;
0 commit comments