Skip to content

Commit

Permalink
fix: output handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kjdev committed Oct 24, 2024
1 parent a746540 commit 5bccbf3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 12 additions & 8 deletions brotli.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ php_brotli_output_handler_init(const char *handler_name,
return NULL;
}

if (!BROTLI_G(output_compression)) {
BROTLI_G(output_compression) = 1;
}

BROTLI_G(handler_registered) = 1;

if (!BROTLI_G(ob_handler)) {
Expand All @@ -366,8 +370,6 @@ php_brotli_output_handler_init(const char *handler_name,
BROTLI_G(ob_handler),
php_brotli_output_handler_context_dtor);

BROTLI_G(output_compression) = 1;

return handler;
}

Expand Down Expand Up @@ -443,6 +445,8 @@ static PHP_INI_MH(OnUpdate_brotli_output_compression)
p = (zend_long *)(base+(size_t) mh_arg1);
*p = int_value;

BROTLI_G(output_compression) = BROTLI_G(output_compression_default);

if (stage == PHP_INI_STAGE_RUNTIME && int_value) {
if (!php_output_handler_started(ZEND_STRL(PHP_BROTLI_OUTPUT_HANDLER))) {
php_brotli_output_compression_start();
Expand All @@ -466,9 +470,10 @@ static int php_brotli_output_conflict(const char *handler_name, size_t handler_n
}

PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("brotli.output_compression", "0",
PHP_INI_ALL, OnUpdate_brotli_output_compression,
output_compression, zend_brotli_globals, brotli_globals)
STD_PHP_INI_BOOLEAN("brotli.output_compression", "0",
PHP_INI_ALL, OnUpdate_brotli_output_compression,
output_compression_default,
zend_brotli_globals, brotli_globals)
STD_PHP_INI_ENTRY("brotli.output_compression_level", "-1",
PHP_INI_ALL, OnUpdateLong, output_compression_level,
zend_brotli_globals, brotli_globals)
Expand Down Expand Up @@ -914,16 +919,15 @@ ZEND_RINIT_FUNCTION(brotli)
{
BROTLI_G(compression_coding) = 0;
if (!BROTLI_G(handler_registered)) {
BROTLI_G(output_compression) = BROTLI_G(output_compression_default);
php_brotli_output_compression_start();
}
return SUCCESS;
}

ZEND_RSHUTDOWN_FUNCTION(brotli)
{
if (BROTLI_G(handler_registered)) {
php_brotli_cleanup_ob_handler_mess();
}
php_brotli_cleanup_ob_handler_mess();
BROTLI_G(handler_registered) = 0;
return SUCCESS;
}
Expand Down
1 change: 1 addition & 0 deletions php_brotli.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef struct _php_brotli_context {

ZEND_BEGIN_MODULE_GLOBALS(brotli)
zend_long output_compression;
zend_long output_compression_default;
zend_long output_compression_level;
zend_bool handler_registered;
int compression_coding;
Expand Down

0 comments on commit 5bccbf3

Please sign in to comment.