diff --git a/src/ngx_pagespeed.cc b/src/ngx_pagespeed.cc index 3f7b7f68a..7b978b637 100644 --- a/src/ngx_pagespeed.cc +++ b/src/ngx_pagespeed.cc @@ -1291,6 +1291,23 @@ ps_loc_conf_t* ps_get_loc_config(ngx_http_request_t* r) { ngx_http_get_module_loc_conf(r, ngx_pagespeed)); } +RewriteOptions* ps_determine_remote_options(ps_srv_conf_t* cfg_s) { + if (!cfg_s || !cfg_s->server_context || + !cfg_s->server_context->global_options()) { + return NULL; + } + if (!cfg_s->server_context->global_options() + ->remote_configuration_url() + .empty()) { + RewriteOptions* remote_options = + cfg_s->server_context->global_options()->Clone(); + // This fetch is blocking for up to remote_configuration_timeout_ms ms. + cfg_s->server_context->GetRemoteOptions(remote_options, false); + return remote_options; + } + return NULL; +} + // Wrapper around GetQueryOptions() RewriteOptions* ps_determine_request_options( ngx_http_request_t* r, @@ -1422,13 +1439,19 @@ bool ps_determine_options(ngx_http_request_t* r, // Start with directory options if we have them, otherwise request options. if (directory_options != NULL) { - *options = directory_options->Clone(); + if (*options != NULL) { + (*options)->Merge(*directory_options); + } else { + *options = directory_options->Clone(); + } } else { - *options = global_options->Clone(); + if (*options == NULL) { + *options = global_options->Clone(); + } } - NgxRewriteDriverFactory* ngx_factory = dynamic_cast( - cfg_s->server_context->factory()); + NgxRewriteDriverFactory* ngx_factory = + dynamic_cast(cfg_s->server_context->factory()); NgxRewriteOptions* ngx_options = dynamic_cast(*options); // ExecuteScriptVariables() sets 'pagespeed off' on ngx_options when execution @@ -1713,10 +1736,9 @@ ngx_int_t ps_resource_handler(ngx_http_request_t* r, RequestContextPtr request_context( cfg_s->server_context->NewRequestContext(r)); - RewriteOptions* options = NULL; GoogleString pagespeed_query_params; GoogleString pagespeed_option_cookies; - + RewriteOptions* options = ps_determine_remote_options(cfg_s); if (!ps_determine_options(r, request_headers.get(), response_headers.get(), &options, request_context, cfg_s, &url, &pagespeed_query_params, &pagespeed_option_cookies, diff --git a/test/nginx_system_test.sh b/test/nginx_system_test.sh index 5884368f5..c85473c99 100644 --- a/test/nginx_system_test.sh +++ b/test/nginx_system_test.sh @@ -31,6 +31,13 @@ : ${NATIVE_FETCHER:?"Set NATIVE_FETCHER to off or on"} : ${PRIMARY_PORT:?"Set PRIMARY_PORT"} : ${SECONDARY_PORT:?"Set SECONDARY_PORT"} +: ${RCPORT1:?"Set RCPORT1"} +: ${RCPORT2:?"Set RCPORT2"} +: ${RCPORT2:?"Set RCPORT3"} +: ${RCPORT4:?"Set RCPORT4"} +: ${RCPORT5:?"Set RCPORT5"} +: ${RCPORT6:?"Set RCPORT6"} +: ${RCPORT7:?"Set RCPORT7"} : ${MOD_PAGESPEED_DIR:?"Set MOD_PAGESPEED_DIR"} : ${NGINX_EXECUTABLE:?"Set NGINX_EXECUTABLE"} POSITION_AUX="${POSITION_AUX:-unset}" @@ -194,6 +201,13 @@ cat $PAGESPEED_CONF_TEMPLATE \ | sed 's#@@SECONDARY_PORT@@#'"$SECONDARY_PORT"'#' \ | sed 's#@@NATIVE_FETCHER@@#'"$NATIVE_FETCHER"'#' \ | sed 's#@@RESOLVER@@#'"$RESOLVER"'#' \ + | sed 's#@@RCPORT1@@#'"$RCPORT1"'#' \ + | sed 's#@@RCPORT2@@#'"$RCPORT2"'#' \ + | sed 's#@@RCPORT3@@#'"$RCPORT3"'#' \ + | sed 's#@@RCPORT4@@#'"$RCPORT4"'#' \ + | sed 's#@@RCPORT5@@#'"$RCPORT5"'#' \ + | sed 's#@@RCPORT6@@#'"$RCPORT6"'#' \ + | sed 's#@@RCPORT7@@#'"$RCPORT7"'#' \ >> $PAGESPEED_CONF # make sure we substituted all the variables check_not_simple grep @@ $PAGESPEED_CONF @@ -1263,6 +1277,10 @@ OUT=$(cat "$ERROR_LOG" \ | grep -v "\\[error\\].*Failed to make directory*" \ | grep -v "\\[error\\].*Could not create directories*" \ | grep -v "\\[error\\].*opening temp file: No such file or directory.*" \ + | grep -v "\\[error\\].*unexpected response.*" \ + | grep -v "\\[error\\].*remote\.cfg.*" \ + | grep -v "\\[warn\\].*remote\.cfg.*" \ + | grep -v "\\[warn\\].*end token not received.*" \ | grep -v "\\[warn\\].*failed to hook next event.*" \ || true) diff --git a/test/pagespeed_test.conf.template b/test/pagespeed_test.conf.template index 425d4e726..ebd8f69b4 100644 --- a/test/pagespeed_test.conf.template +++ b/test/pagespeed_test.conf.template @@ -1078,6 +1078,56 @@ http { pagespeed DisableFilters remove_comments,add_instrumentation; } + # Start remote config servers. + server { + listen @@SECONDARY_PORT@@; + listen [::]:@@SECONDARY_PORT@@; + server_name remote-config.example.com; + pagespeed FileCachePath "@@SECONDARY_CACHE@@"; + pagespeed RemoteConfigurationUrl "http://127.0.0.1:@@RCPORT1@@/remote.cfg"; + pagespeed RemoteConfigurationTimeoutMs 1500; + } + server { + listen @@SECONDARY_PORT@@; + listen [::]:@@SECONDARY_PORT@@; + server_name remote-config-partially-invalid.example.com; + pagespeed FileCachePath "@@SECONDARY_CACHE@@"; + pagespeed RemoteConfigurationUrl "http://127.0.0.1:@@RCPORT2@@/remote.cfg"; + pagespeed RemoteConfigurationTimeoutMs 1500; + } + server { + listen @@SECONDARY_PORT@@; + listen [::]:@@SECONDARY_PORT@@; + server_name remote-config-invalid.example.com; + pagespeed FileCachePath "@@SECONDARY_CACHE@@"; + pagespeed RemoteConfigurationUrl "http://127.0.0.1:@@RCPORT3@@/remote.cfg"; + pagespeed RemoteConfigurationTimeoutMs 1500; + } + server { + listen @@SECONDARY_PORT@@; + listen [::]:@@SECONDARY_PORT@@; + server_name remote-config-failed-fetch.example.com; + pagespeed FileCachePath "@@SECONDARY_CACHE@@"; + pagespeed RemoteConfigurationUrl "http://127.0.0.1:@@RCPORT5@@/remote.cfg"; + pagespeed RemoteConfigurationTimeoutMs 1500; + } + server { + listen @@SECONDARY_PORT@@; + listen [::]:@@SECONDARY_PORT@@; + server_name remote-config-slow-fetch.example.com; + pagespeed FileCachePath "@@SECONDARY_CACHE@@"; + pagespeed RemoteConfigurationUrl "http://127.0.0.1:@@RCPORT6@@/remote.cfg"; + pagespeed RemoteConfigurationTimeoutMs 1500; + } + server { + listen @@SECONDARY_PORT@@; + listen [::]:@@SECONDARY_PORT@@; + server_name remote-config-experiment.example.com; + pagespeed FileCachePath "@@SECONDARY_CACHE@@"; + pagespeed RemoteConfigurationUrl "http://127.0.0.1:@@RCPORT7@@/remote.cfg"; + pagespeed RemoteConfigurationTimeoutMs 1500; + } + # Proxy + IPRO a gzip'd file for testing Issue 896. server { listen @@SECONDARY_PORT@@; diff --git a/test/run_tests.sh b/test/run_tests.sh index 25fb9194e..f21e626af 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -53,6 +53,13 @@ PRIMARY_PORT="$1" SECONDARY_PORT="$2" MOD_PAGESPEED_DIR="$3" NGINX_EXECUTABLE="$4" +RCPORT1=9991 +RCPORT2=9992 +RCPORT3=9993 +RCPORT4=9994 +RCPORT5=9995 +RCPORT6=9996 +RCPORT7=9997 this_dir="$( cd $(dirname "$0") && pwd)" @@ -63,6 +70,13 @@ function run_test_checking_failure() { MOD_PAGESPEED_DIR="$MOD_PAGESPEED_DIR" \ NGINX_EXECUTABLE="$NGINX_EXECUTABLE" \ RUN_TESTS="$RUN_TESTS" \ + RCPORT1="$RCPORT1" \ + RCPORT2="$RCPORT2" \ + RCPORT3="$RCPORT3" \ + RCPORT4="$RCPORT4" \ + RCPORT5="$RCPORT5" \ + RCPORT6="$RCPORT6" \ + RCPORT7="$RCPORT7" \ bash "$this_dir/nginx_system_test.sh" STATUS=$? echo "With $@ setup."