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

Commit f78058b

Browse files
authored
Allow use of "unplugged" without crashing (#1362)
* update mps * stop crashing when unplugged * formatting fixes
1 parent 8a0b080 commit f78058b

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/ngx_pagespeed.cc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,11 @@ ngx_command_t ps_commands[] = {
749749
ngx_null_command
750750
};
751751

752+
bool ps_disabled(ps_srv_conf_t* cfg_s) {
753+
return cfg_s->server_context == NULL ||
754+
cfg_s->server_context->config()->unplugged();
755+
}
756+
752757
void ps_ignore_sigpipe() {
753758
struct sigaction act;
754759
ngx_memzero(&act, sizeof(act));
@@ -881,8 +886,7 @@ char* ps_configure(ngx_conf_t* cf,
881886
ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(
882887
ngx_http_cycle_get_module_main_conf(cf->cycle, ngx_pagespeed));
883888
if (*options == NULL) {
884-
*options = new NgxRewriteOptions(
885-
cfg_m->driver_factory->thread_system());
889+
*options = new NgxRewriteOptions(cfg_m->driver_factory->thread_system());
886890
}
887891

888892
ProcessScriptVariablesMode script_mode =
@@ -1191,7 +1195,7 @@ char* ps_merge_loc_conf(ngx_conf_t* cf, void* parent, void* child) {
11911195
ps_srv_conf_t* cfg_s = static_cast<ps_srv_conf_t*>(
11921196
ngx_http_conf_get_module_srv_conf(cf, ngx_pagespeed));
11931197

1194-
if (cfg_s->server_context == NULL) {
1198+
if (ps_disabled(cfg_s)) {
11951199
// Pagespeed options cannot be defined only in location blocks. There must
11961200
// be at least a single "pagespeed off" in the main block or a server
11971201
// block.
@@ -1698,7 +1702,7 @@ void ps_release_request_context(void* data) {
16981702
RequestRouting::Response ps_route_request(ngx_http_request_t* r) {
16991703
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
17001704

1701-
if (!cfg_s->server_context->global_options()->enabled()) {
1705+
if (ps_disabled(cfg_s)) {
17021706
// Not enabled for this server block.
17031707
return RequestRouting::kPagespeedDisabled;
17041708
}
@@ -2050,8 +2054,8 @@ ngx_int_t ps_resource_handler(ngx_http_request_t* r,
20502054
if (options->in_place_rewriting_enabled() &&
20512055
options->enabled() &&
20522056
options->IsAllowed(url.Spec())) {
2053-
ps_create_base_fetch(url.Spec(), ctx, request_context, request_headers.release(),
2054-
kIproLookup, options);
2057+
ps_create_base_fetch(url.Spec(), ctx, request_context,
2058+
request_headers.release(), kIproLookup, options);
20552059

20562060
// Do not store driver in request_context, it's not safe.
20572061
RewriteDriver* driver;
@@ -2277,8 +2281,7 @@ ngx_http_output_body_filter_pt ngx_http_next_body_filter;
22772281
// nginx so it can send them out to the browser.
22782282
ngx_int_t ps_html_rewrite_header_filter(ngx_http_request_t* r) {
22792283
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
2280-
if (cfg_s->server_context == NULL) {
2281-
// Pagespeed is on for some server block but not this one.
2284+
if (ps_disabled(cfg_s)) {
22822285
return ngx_http_next_header_filter(r);
22832286
}
22842287

@@ -2362,8 +2365,7 @@ ngx_int_t ps_html_rewrite_header_filter(ngx_http_request_t* r) {
23622365

23632366
ngx_int_t ps_html_rewrite_body_filter(ngx_http_request_t* r, ngx_chain_t* in) {
23642367
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
2365-
if (cfg_s->server_context == NULL) {
2366-
// Pagespeed is on for some server block but not this one.
2368+
if (ps_disabled(cfg_s)) {
23672369
return ngx_http_next_body_filter(r, in);
23682370
}
23692371

@@ -2887,8 +2889,8 @@ ngx_int_t ps_beacon_handler(ngx_http_request_t* r) {
28872889
// supply it to the user.
28882890
ngx_int_t ps_content_handler(ngx_http_request_t* r) {
28892891
ps_srv_conf_t* cfg_s = ps_get_srv_config(r);
2890-
if (cfg_s->server_context == NULL) {
2891-
// Pagespeed is on for some server block but not this one.
2892+
if (ps_disabled(cfg_s)) {
2893+
// Pagespeed is not on for this server block.
28922894
return NGX_DECLINED;
28932895
}
28942896

0 commit comments

Comments
 (0)