Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 2a40977

Browse files
committed
Merge pull request #859 from We-Amp/keesspoelstra-gzip-init-fix
NgxGZipSetter fix, at config reload Init did not work as expected (Issue 844)
2 parents 0980633 + c3f4151 commit 2a40977

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/ngx_gzip_setter.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extern "C" {
7070
}
7171
}
7272

73-
NgxGZipSetter::NgxGZipSetter() : enabled_(0) { }
73+
NgxGZipSetter::NgxGZipSetter() : enabled_(false), initialized_(false) { }
7474
NgxGZipSetter::~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_) {

src/ngx_gzip_setter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class NgxGZipSetter {
9191
ngx_command_ctx gzip_vary_command_;
9292
ngx_command_ctx gzip_http_version_command_;
9393
bool enabled_;
94+
bool initialized_;
9495

9596
public:
9697
NgxGZipSetter();

0 commit comments

Comments
 (0)