@@ -70,7 +70,7 @@ extern "C" {
7070 }
7171}
7272
73- NgxGZipSetter::NgxGZipSetter () : enabled_(0 ) { }
73+ NgxGZipSetter::NgxGZipSetter () : enabled_(false ), initialized_( false ) { }
7474NgxGZipSetter::~NgxGZipSetter () { }
7575
7676// Helper functions to determine signature.
@@ -95,7 +95,7 @@ bool IsNgxBitmaskCommand(ngx_command_t* command) {
9595 HasLocalConfig (command));
9696}
9797
98- // Initialize the NgxGzipSetter .
98+ // Initialize the NgxGZipSetter .
9999// Find the gzip, gzip_vary, gzip_http_version and gzip_types commands in the
100100// gzip module. Enable if the signature of the zip command matches with what we
101101// trust. Also sets up redirects for the configurations. These redirect handle
@@ -105,6 +105,16 @@ void NgxGZipSetter::Init(ngx_conf_t* cf) {
105105#if (NGX_HTTP_GZIP)
106106 bool gzip_signature_mismatch = false ;
107107 bool other_signature_mismatch = false ;
108+ // If we initialized already we don't have to scan again.
109+ if (initialized_) {
110+ // Config might have changed, so re-enable if we have gzip.
111+ if (gzip_command_.command_ != NULL ) {
112+ enabled_ = true ;
113+ } else {
114+ enabled_ = false ;
115+ }
116+ return ;
117+ }
108118 for (int m = 0 ; ngx_modules[m] != NULL ; m++) {
109119 if (ngx_modules[m]->commands != NULL ) {
110120 for (int c = 0 ; ngx_modules[m]->commands [c].name .len ; c++) {
@@ -122,7 +132,7 @@ void NgxGZipSetter::Init(ngx_conf_t* cf) {
122132 current_command->set = ngx_gzip_redirect_conf_set_flag_slot;
123133 gzip_command_.command_ = current_command;
124134 gzip_command_.module_ = ngx_modules[m];
125- enabled_ = 1 ;
135+ enabled_ = true ;
126136 } else {
127137 ngx_conf_log_error (
128138 NGX_LOG_WARN, cf, 0 ,
@@ -189,6 +199,7 @@ void NgxGZipSetter::Init(ngx_conf_t* cf) {
189199 }
190200 }
191201 }
202+ initialized_ = true ;
192203 if (gzip_signature_mismatch) {
193204 return ; // Already logged error.
194205 } else if (!enabled_) {
0 commit comments