standby: add standby mode (#1365)
* standby: add standby mode Add standby mode for ngx_pagespeed, equivalent to "off" in mod_pagespeed. With this change "off" is deprecated, and people should use "unplugged" instead. * Update mps to include test file * update mps * update mps * update mps
This commit is contained in:
+14
-7
@@ -1152,13 +1152,17 @@ char* ps_merge_srv_conf(ngx_conf_t* cf, void* parent, void* child) {
|
|||||||
delete cfg_s->options;
|
delete cfg_s->options;
|
||||||
cfg_s->options = NULL;
|
cfg_s->options = NULL;
|
||||||
|
|
||||||
if (cfg_s->server_context->global_options()->enabled()) {
|
if (!cfg_s->server_context->global_options()->unplugged()) {
|
||||||
// Validate FileCachePath
|
// Validate FileCachePath
|
||||||
GoogleMessageHandler handler;
|
GoogleMessageHandler handler;
|
||||||
const char* file_cache_path =
|
const char* file_cache_path =
|
||||||
cfg_s->server_context->config()->file_cache_path().c_str();
|
cfg_s->server_context->config()->file_cache_path().c_str();
|
||||||
if (file_cache_path[0] == '\0') {
|
if (file_cache_path[0] == '\0') {
|
||||||
return const_cast<char*>("FileCachePath must be set");
|
if (!cfg_s->server_context->global_options()->standby()) {
|
||||||
|
return const_cast<char*>("FileCachePath must be set, even for standby");
|
||||||
|
} else {
|
||||||
|
return const_cast<char*>("FileCachePath must be set");
|
||||||
|
}
|
||||||
} else if (!cfg_m->driver_factory->file_system()->IsDir(
|
} else if (!cfg_m->driver_factory->file_system()->IsDir(
|
||||||
file_cache_path, &handler).is_true()) {
|
file_cache_path, &handler).is_true()) {
|
||||||
return const_cast<char*>(
|
return const_cast<char*>(
|
||||||
@@ -1844,11 +1848,6 @@ ngx_int_t ps_resource_handler(ngx_http_request_t* r,
|
|||||||
options = cfg_s->server_context->global_options();
|
options = cfg_s->server_context->global_options();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options->enabled()) {
|
|
||||||
// Disabled via query params or request headers.
|
|
||||||
return NGX_DECLINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
request_context->set_options(options->ComputeHttpOptions());
|
request_context->set_options(options->ComputeHttpOptions());
|
||||||
|
|
||||||
// ps_determine_options modified url, removing any ModPagespeedFoo=Bar query
|
// ps_determine_options modified url, removing any ModPagespeedFoo=Bar query
|
||||||
@@ -1875,6 +1874,14 @@ ngx_int_t ps_resource_handler(ngx_http_request_t* r,
|
|||||||
response_category == RequestRouting::kGlobalAdmin ||
|
response_category == RequestRouting::kGlobalAdmin ||
|
||||||
response_category == RequestRouting::kCachePurge;
|
response_category == RequestRouting::kCachePurge;
|
||||||
|
|
||||||
|
// Normally if we're disabled we won't handle any requests, but if we're in
|
||||||
|
// standby mode we do want to handle requests for .pagespeed. resources.
|
||||||
|
if (options->unplugged() ||
|
||||||
|
(!options->enabled() && !pagespeed_resource)) {
|
||||||
|
// Disabled via query params or request headers.
|
||||||
|
return NGX_DECLINED;
|
||||||
|
}
|
||||||
|
|
||||||
if (!html_rewrite) {
|
if (!html_rewrite) {
|
||||||
// create request ctx
|
// create request ctx
|
||||||
CHECK(ctx == NULL);
|
CHECK(ctx == NULL);
|
||||||
|
|||||||
@@ -192,15 +192,18 @@ RewriteOptions::OptionScope NgxRewriteOptions::GetOptionScope(
|
|||||||
|
|
||||||
RewriteOptions::OptionSettingResult NgxRewriteOptions::ParseAndSetOptions0(
|
RewriteOptions::OptionSettingResult NgxRewriteOptions::ParseAndSetOptions0(
|
||||||
StringPiece directive, GoogleString* msg, MessageHandler* handler) {
|
StringPiece directive, GoogleString* msg, MessageHandler* handler) {
|
||||||
if (IsDirective(directive, "on")) {
|
EnabledEnum enabled;
|
||||||
set_enabled(RewriteOptions::kEnabledOn);
|
if (!ParseFromString(directive, &enabled)) {
|
||||||
} else if (IsDirective(directive, "off")) {
|
|
||||||
set_enabled(RewriteOptions::kEnabledOff);
|
|
||||||
} else if (IsDirective(directive, "unplugged")) {
|
|
||||||
set_enabled(RewriteOptions::kEnabledUnplugged);
|
|
||||||
} else {
|
|
||||||
return RewriteOptions::kOptionNameUnknown;
|
return RewriteOptions::kOptionNameUnknown;
|
||||||
}
|
}
|
||||||
|
if (enabled == RewriteOptions::kEnabledOff) {
|
||||||
|
// In ngx_pagespeed, for historical reasons, we treat "off" as "unplugged".
|
||||||
|
// Also, "off" is deprecated and people should be using "standby" or
|
||||||
|
// "unplugged" now depending on which sense they want. See comment on
|
||||||
|
// RewriteOptions::EnabledEnum.
|
||||||
|
enabled = RewriteOptions::kEnabledUnplugged;
|
||||||
|
}
|
||||||
|
set_enabled(enabled);
|
||||||
return RewriteOptions::kOptionOk;
|
return RewriteOptions::kOptionOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,42 @@ http {
|
|||||||
"@@SERVER_ROOT@@/mod_pagespeed_example/styles/";
|
"@@SERVER_ROOT@@/mod_pagespeed_example/styles/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen @@SECONDARY_PORT@@;
|
||||||
|
listen [::]:@@SECONDARY_PORT@@;
|
||||||
|
server_name pagespeed-off.example.com;
|
||||||
|
pagespeed FileCachePath "@@FILE_CACHE@@";
|
||||||
|
pagespeed off;
|
||||||
|
pagespeed EnableFilters collapse_whitespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen @@SECONDARY_PORT@@;
|
||||||
|
listen [::]:@@SECONDARY_PORT@@;
|
||||||
|
server_name pagespeed-on.example.com;
|
||||||
|
pagespeed FileCachePath "@@FILE_CACHE@@";
|
||||||
|
pagespeed on;
|
||||||
|
pagespeed EnableFilters collapse_whitespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen @@SECONDARY_PORT@@;
|
||||||
|
listen [::]:@@SECONDARY_PORT@@;
|
||||||
|
server_name pagespeed-standby.example.com;
|
||||||
|
pagespeed FileCachePath "@@FILE_CACHE@@";
|
||||||
|
pagespeed standby;
|
||||||
|
pagespeed EnableFilters collapse_whitespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen @@SECONDARY_PORT@@;
|
||||||
|
listen [::]:@@SECONDARY_PORT@@;
|
||||||
|
server_name pagespeed-unplugged.example.com;
|
||||||
|
pagespeed FileCachePath "@@FILE_CACHE@@";
|
||||||
|
pagespeed unplugged;
|
||||||
|
pagespeed EnableFilters collapse_whitespace;
|
||||||
|
}
|
||||||
|
|
||||||
pagespeed UseNativeFetcher "@@NATIVE_FETCHER@@";
|
pagespeed UseNativeFetcher "@@NATIVE_FETCHER@@";
|
||||||
@@RESOLVER@@
|
@@RESOLVER@@
|
||||||
|
|
||||||
|
|||||||
Submodule testing-dependencies/mod_pagespeed updated: c50a93f2e8...a41cdab05e
Reference in New Issue
Block a user