IPRO+MPD: Make In-Place-Resource-Optimization with MapProxyDomain work

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1015

Pull with MPS Side for this change:
https://github.com/pagespeed/mod_pagespeed/pull/1161
This commit is contained in:
Otto van der Schaaf
2015-10-26 05:25:03 +01:00
parent d30972985b
commit 634b813071
7 changed files with 52 additions and 6 deletions
+2
View File
@@ -111,6 +111,8 @@ const char* BaseFetchTypeToCStr(NgxBaseFetchType type) {
return "admin page";
case kIproLookup:
return "ipro lookup";
case kPageSpeedProxy:
return "pagespeed proxy";
}
CHECK(false);
return "can't get here";
+2 -1
View File
@@ -68,7 +68,8 @@ enum NgxBaseFetchType {
kIproLookup,
kHtmlTransform,
kPageSpeedResource,
kAdminPage
kAdminPage,
kPageSpeedProxy
};
class NgxBaseFetch : public AsyncFetch {
+30
View File
@@ -1882,6 +1882,35 @@ ngx_int_t ps_resource_handler(ngx_http_request_t* r,
}
return ps_async_wait_response(r);
} else if (!html_rewrite && response_category == RequestRouting::kResource) {
bool is_proxy = false;
GoogleString mapped_url;
GoogleString host_header;
if (options->domain_lawyer()->MapOriginUrl(
url, &mapped_url, &host_header, &is_proxy) && is_proxy) {
ps_create_base_fetch(ctx, request_context, request_headers.release(),
kPageSpeedProxy);
RewriteDriver* driver;
if (custom_options.get() == NULL) {
driver = cfg_s->server_context->NewRewriteDriver(
ctx->base_fetch->request_context());
} else {
driver = cfg_s->server_context->NewCustomRewriteDriver(
custom_options.release(), ctx->base_fetch->request_context());
}
driver->SetRequestHeaders(*ctx->base_fetch->request_headers());
driver->set_pagespeed_query_params(pagespeed_query_params);
driver->set_pagespeed_option_cookies(pagespeed_option_cookies);
cfg_s->proxy_fetch_factory->StartNewProxyFetch(
mapped_url, ctx->base_fetch, driver, NULL /*property_callback*/,
NULL /*original_content_fetch*/);
return ps_async_wait_response(r);
}
}
if (html_rewrite) {
@@ -1923,6 +1952,7 @@ ngx_int_t ps_resource_handler(ngx_http_request_t* r,
url_string, ctx->base_fetch, driver,
property_callback,
NULL /* original_content_fetch */);
ctx->proxy_fetch->set_trusted_input(true);
return NGX_OK;
}
+3 -2
View File
@@ -40,8 +40,9 @@ class NgxServerContext : public SystemServerContext {
NgxRewriteDriverFactory* factory, StringPiece hostname, int port);
virtual ~NgxServerContext();
// We expect to use ProxyFetch with HTML.
virtual bool ProxiesHtml() const { return true; }
// We don't allow ProxyFetch to fetch HTML via MapProxyDomain. We will call
// set_trusted_input() on any ProxyFetches we use to transform internal HTML.
virtual bool ProxiesHtml() const { return false; }
// Call only when you need an NgxRewriteOptions. If you don't need
// nginx-specific behavior, call global_options() instead which doesn't
+2
View File
@@ -40,6 +40,7 @@
: ${RCPORT7:?"Set RCPORT7"}
: ${MOD_PAGESPEED_DIR:?"Set MOD_PAGESPEED_DIR"}
: ${NGINX_EXECUTABLE:?"Set NGINX_EXECUTABLE"}
: ${PAGESPEED_TEST_HOST:?"Set PAGESPEED_TEST_HOST"}
POSITION_AUX="${POSITION_AUX:-unset}"
PRIMARY_HOSTNAME="localhost:$PRIMARY_PORT"
@@ -208,6 +209,7 @@ cat $PAGESPEED_CONF_TEMPLATE \
| sed 's#@@RCPORT5@@#'"$RCPORT5"'#' \
| sed 's#@@RCPORT6@@#'"$RCPORT6"'#' \
| sed 's#@@RCPORT7@@#'"$RCPORT7"'#' \
| sed 's#@@PAGESPEED_TEST_HOST@@#'"$PAGESPEED_TEST_HOST"'#' \
>> $PAGESPEED_CONF
# make sure we substituted all the variables
check_not_simple grep @@ $PAGESPEED_CONF
+8
View File
@@ -1401,6 +1401,14 @@ http {
http://www.modpagespeed.com/rewrite_javascript.js;
pagespeed RetainComment " google_ad_section*";
# Test proxying of non-.pagespeed. resources.
pagespeed MapProxyDomain http://localhost:@@PRIMARY_PORT@@/modpagespeed_http
http://@@PAGESPEED_TEST_HOST@@/do_not_modify;
pagespeed MapProxyDomain http://localhost:@@PRIMARY_PORT@@/content_type_present
http://@@PAGESPEED_TEST_HOST@@:8091;
pagespeed MapProxyDomain http://localhost:@@PRIMARY_PORT@@/content_type_absent
http://@@PAGESPEED_TEST_HOST@@:8092;
add_header X-Extra-Header 1;
# Establish a proxy mapping where the current server proxies an image
+5 -3
View File
@@ -23,9 +23,9 @@
# Exits with status 2 if command line args are wrong.
#
# Usage:
# ./run_tests.sh primary_port secondary_port mod_pagespeed_dir
# ./run_tests.sh primary_port secondary_port mod_pagespeed_dir pagespeed_test_host
# Example:
# ./run_tests.sh 8050 8051 /path/to/mod_pagespeed
# ./run_tests.sh 8050 8051 /path/to/mod_pagespeed www.modpagespeed.com
#
# Normally we test only with the native fetcher off. Set
@@ -43,7 +43,7 @@ RUN_TESTS=${RUN_TESTS:-true}
# true.
USE_VALGRIND=${USE_VALGRIND:-false}
if [ "$#" -ne 4 ] ; then
if [ "$#" -ne 5 ] ; then
echo "Usage: $0 primary_port secondary_port mod_pagespeed_dir"
echo " nginx_executable"
exit 2
@@ -53,6 +53,7 @@ PRIMARY_PORT="$1"
SECONDARY_PORT="$2"
MOD_PAGESPEED_DIR="$3"
NGINX_EXECUTABLE="$4"
PAGESPEED_TEST_HOST="$5"
RCPORT1=9991
RCPORT2=9992
RCPORT3=9993
@@ -69,6 +70,7 @@ function run_test_checking_failure() {
SECONDARY_PORT="$SECONDARY_PORT" \
MOD_PAGESPEED_DIR="$MOD_PAGESPEED_DIR" \
NGINX_EXECUTABLE="$NGINX_EXECUTABLE" \
PAGESPEED_TEST_HOST="$PAGESPEED_TEST_HOST" \
RUN_TESTS="$RUN_TESTS" \
RCPORT1="$RCPORT1" \
RCPORT2="$RCPORT2" \