@@ -356,10 +356,23 @@ static int php_brotli_output_encoding(void)
356
356
return BROTLI_G (compression_coding );
357
357
}
358
358
359
+ static int php_brotli_output_handler_context_start (php_brotli_context * ctx )
360
+ {
361
+ long level = BROTLI_G (output_compression_level );
362
+
363
+ int result = php_brotli_context_create_encoder_ex (ctx ,
364
+ level ,
365
+ BROTLI_DEFAULT_WINDOW ,
366
+ BROTLI_MODE_GENERIC ,
367
+ dict ,
368
+ 0 );
369
+
370
+ return result ;
371
+ }
372
+
359
373
static int php_brotli_output_handler (void * * handler_context ,
360
374
php_output_context * output_context )
361
375
{
362
- long level = BROTLI_DEFAULT_QUALITY ;
363
376
php_brotli_context * ctx = * (php_brotli_context * * )handler_context ;
364
377
365
378
if (!php_brotli_output_encoding ()) {
@@ -377,13 +390,8 @@ static int php_brotli_output_handler(void **handler_context,
377
390
return FAILURE ;
378
391
}
379
392
380
- level = BROTLI_G (output_compression_level );
381
- if (level < BROTLI_MIN_QUALITY || level > BROTLI_MAX_QUALITY ) {
382
- level = BROTLI_DEFAULT_QUALITY ;
383
- }
384
-
385
393
if (output_context -> op & PHP_OUTPUT_HANDLER_START ) {
386
- if (php_brotli_context_create_encoder (ctx , level , 0 , 0 ) != SUCCESS ) {
394
+ if (php_brotli_output_handler_context_start (ctx ) != SUCCESS ) {
387
395
return FAILURE ;
388
396
}
389
397
}
@@ -455,8 +463,7 @@ static int php_brotli_output_handler(void **handler_context,
455
463
return SUCCESS ;
456
464
} else {
457
465
// restart
458
- if (php_brotli_context_create_encoder (ctx ,
459
- level , 0 , 0 ) != SUCCESS ) {
466
+ if (php_brotli_output_handler_context_start (ctx ) != SUCCESS ) {
460
467
return FAILURE ;
461
468
}
462
469
}
@@ -614,12 +621,16 @@ static int php_brotli_output_conflict(const char *handler_name, size_t handler_n
614
621
return SUCCESS ;
615
622
}
616
623
624
+ #define STRINGIFY (n ) #n
625
+ #define TOSTRING (n ) STRINGIFY(n)
626
+
617
627
PHP_INI_BEGIN ()
618
628
STD_PHP_INI_BOOLEAN ("brotli.output_compression" , "0" ,
619
629
PHP_INI_ALL , OnUpdate_brotli_output_compression ,
620
630
output_compression_default ,
621
631
zend_brotli_globals , brotli_globals )
622
- STD_PHP_INI_ENTRY ("brotli.output_compression_level" , "-1" ,
632
+ STD_PHP_INI_ENTRY ("brotli.output_compression_level" ,
633
+ TOSTRING (BROTLI_DEFAULT_QUALITY ),
623
634
PHP_INI_ALL , OnUpdateLong , output_compression_level ,
624
635
zend_brotli_globals , brotli_globals )
625
636
PHP_INI_END ()
0 commit comments