Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b26e174d8b | |||
| 026f86dfc2 | |||
| 0db78f6e8c | |||
| 4af79a1e2b | |||
| ed20dabf66 | |||
| 067764aa92 | |||
| 84ab39e8e3 | |||
| 2cfbec12c5 | |||
| 9fd8c6f1bb | |||
| 1051a90c4e | |||
| 21a4a83b77 | |||
| 2b4c097d48 | |||
| 181875e80b | |||
| 371293af48 | |||
| ba78a8542b | |||
| 306cdf358a | |||
| 8ff08ed7e9 | |||
| fab4aac24e | |||
| 88e3d48d23 | |||
| 4ec7afe5a8 | |||
| 751f532162 | |||
| fbde0ace7e | |||
| 13e99f631b | |||
| 1c6c9f1a32 | |||
| daa6031294 | |||
| 5446303610 | |||
| 6c3cc29def | |||
| 17e8c7535a | |||
| 01e458ca0d |
@@ -29,8 +29,8 @@ if [ "$mod_pagespeed_dir" = "unset" ] ; then
|
||||
echo " You need to separately download the pagespeed library:"
|
||||
echo ""
|
||||
echo " $ cd /path/to/ngx_pagespeed"
|
||||
echo " $ wget https://dl.google.com/dl/page-speed/psol/1.10.33.2.tar.gz"
|
||||
echo " $ tar -xzvf 1.10.33.2.tar.gz # expands to psol/"
|
||||
echo " $ wget https://dl.google.com/dl/page-speed/psol/1.11.33.2.tar.gz"
|
||||
echo " $ tar -xzvf 1.11.33.2.tar.gz # expands to psol/"
|
||||
echo ""
|
||||
echo " Or see the installation instructions:"
|
||||
echo " https://github.com/pagespeed/ngx_pagespeed#how-to-build"
|
||||
@@ -118,6 +118,13 @@ case "$NGX_GCC_VER" in
|
||||
;;
|
||||
esac
|
||||
|
||||
# workaround for a bug in nginx-1.9.11, see:
|
||||
# http://hg.nginx.org/nginx/rev/ff1e625ae55b
|
||||
NGX_VERSION=`grep nginx_version src/core/nginx.h | sed -e 's/^.* \(.*\)$/\1/'`
|
||||
if [ "$NGX_VERSION" = "1009011" ]; then
|
||||
CFLAGS="$CFLAGS -Wno-write-strings"
|
||||
fi
|
||||
|
||||
if [ "$WNO_ERROR" = "YES" ]; then
|
||||
CFLAGS="$CFLAGS -Wno-error"
|
||||
fi
|
||||
@@ -186,65 +193,7 @@ ngx_feature_test="
|
||||
# Test whether we have pagespeed and can compile and link against it.
|
||||
. "$ngx_addon_dir/cpp_feature"
|
||||
|
||||
if [ $ngx_found = yes ]; then
|
||||
ps_src="$ngx_addon_dir/src"
|
||||
ngx_addon_name=ngx_pagespeed
|
||||
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
|
||||
$ps_src/log_message_handler.h \
|
||||
$ps_src/ngx_base_fetch.h \
|
||||
$ps_src/ngx_caching_headers.h \
|
||||
$ps_src/ngx_event_connection.h \
|
||||
$ps_src/ngx_fetch.h \
|
||||
$ps_src/ngx_gzip_setter.h \
|
||||
$ps_src/ngx_list_iterator.h \
|
||||
$ps_src/ngx_message_handler.h \
|
||||
$ps_src/ngx_pagespeed.h \
|
||||
$ps_src/ngx_rewrite_driver_factory.h \
|
||||
$ps_src/ngx_rewrite_options.h \
|
||||
$ps_src/ngx_server_context.h \
|
||||
$ps_src/ngx_url_async_fetcher.h \
|
||||
$psol_binary"
|
||||
NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
|
||||
$ps_src/log_message_handler.cc \
|
||||
$ps_src/ngx_base_fetch.cc \
|
||||
$ps_src/ngx_caching_headers.cc \
|
||||
$ps_src/ngx_event_connection.cc \
|
||||
$ps_src/ngx_fetch.cc \
|
||||
$ps_src/ngx_gzip_setter.cc \
|
||||
$ps_src/ngx_list_iterator.cc \
|
||||
$ps_src/ngx_message_handler.cc \
|
||||
$ps_src/ngx_pagespeed.cc \
|
||||
$ps_src/ngx_rewrite_driver_factory.cc \
|
||||
$ps_src/ngx_rewrite_options.cc \
|
||||
$ps_src/ngx_server_context.cc \
|
||||
$ps_src/ngx_url_async_fetcher.cc"
|
||||
# Save our sources in a separate var since we may need it in config.make
|
||||
PS_NGX_SRCS="$NGX_ADDON_SRCS"
|
||||
|
||||
if [ "$position_aux" = "true" ] ; then
|
||||
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES $ngx_addon_name"
|
||||
else
|
||||
# Make pagespeed run immediately before gzip and Brotli.
|
||||
if echo $HTTP_FILTER_MODULES | grep ngx_http_brotli_filter_module >/dev/null; then
|
||||
module=ngx_http_brotli_filter_module
|
||||
elif [ $HTTP_GZIP = YES ]; then
|
||||
module=$HTTP_GZIP_FILTER_MODULE
|
||||
else
|
||||
module=$HTTP_RANGE_HEADER_FILTER_MODULE
|
||||
fi
|
||||
|
||||
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES |\
|
||||
sed "s/$module/$module $ngx_addon_name/")
|
||||
fi
|
||||
|
||||
# Make the etag header filter run immediately before range header filter.
|
||||
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES |\
|
||||
sed "s/$HTTP_RANGE_HEADER_FILTER_MODULE/$HTTP_RANGE_HEADER_FILTER_MODULE ngx_pagespeed_etag_filter/")
|
||||
|
||||
CORE_LIBS="$CORE_LIBS $pagespeed_libs"
|
||||
CORE_INCS="$CORE_INCS $pagespeed_include"
|
||||
echo "List of modules (in reverse order of applicability): "$HTTP_FILTER_MODULES
|
||||
else
|
||||
if [ $ngx_found = no ]; then
|
||||
cat << END
|
||||
$0: error: module ngx_pagespeed requires the pagespeed optimization library.
|
||||
Look in obj/autoconf.err for more details.
|
||||
@@ -252,6 +201,115 @@ END
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ps_src="$ngx_addon_dir/src"
|
||||
ngx_addon_name=ngx_pagespeed
|
||||
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
|
||||
$ps_src/log_message_handler.h \
|
||||
$ps_src/ngx_base_fetch.h \
|
||||
$ps_src/ngx_caching_headers.h \
|
||||
$ps_src/ngx_event_connection.h \
|
||||
$ps_src/ngx_fetch.h \
|
||||
$ps_src/ngx_gzip_setter.h \
|
||||
$ps_src/ngx_list_iterator.h \
|
||||
$ps_src/ngx_message_handler.h \
|
||||
$ps_src/ngx_pagespeed.h \
|
||||
$ps_src/ngx_rewrite_driver_factory.h \
|
||||
$ps_src/ngx_rewrite_options.h \
|
||||
$ps_src/ngx_server_context.h \
|
||||
$ps_src/ngx_url_async_fetcher.h \
|
||||
$psol_binary"
|
||||
NPS_SRCS=" \
|
||||
$ps_src/log_message_handler.cc \
|
||||
$ps_src/ngx_base_fetch.cc \
|
||||
$ps_src/ngx_caching_headers.cc \
|
||||
$ps_src/ngx_event_connection.cc \
|
||||
$ps_src/ngx_fetch.cc \
|
||||
$ps_src/ngx_gzip_setter.cc \
|
||||
$ps_src/ngx_list_iterator.cc \
|
||||
$ps_src/ngx_message_handler.cc \
|
||||
$ps_src/ngx_pagespeed.cc \
|
||||
$ps_src/ngx_rewrite_driver_factory.cc \
|
||||
$ps_src/ngx_rewrite_options.cc \
|
||||
$ps_src/ngx_server_context.cc \
|
||||
$ps_src/ngx_url_async_fetcher.cc"
|
||||
# Save our sources in a separate var since we may need it in config.make
|
||||
PS_NGX_SRCS="$NGX_ADDON_SRCS \
|
||||
$NPS_SRCS"
|
||||
|
||||
# Make pagespeed run immediately before gzip and Brotli.
|
||||
if echo $HTTP_FILTER_MODULES | grep ngx_http_brotli_filter_module >/dev/null; then
|
||||
next=ngx_http_brotli_filter_module
|
||||
elif [ $HTTP_GZIP = YES ]; then
|
||||
next=ngx_http_gzip_filter_module
|
||||
else
|
||||
next=ngx_http_range_header_filter_module
|
||||
fi
|
||||
|
||||
if [ -n "$ngx_module_link" ]; then
|
||||
# nginx-1.9.11+
|
||||
ngx_module_type=HTTP_FILTER
|
||||
ngx_module_name="ngx_pagespeed ngx_pagespeed_etag_filter"
|
||||
ngx_module_incs="$ngx_feature_path"
|
||||
ngx_module_deps=
|
||||
ngx_module_srcs="$NPS_SRCS"
|
||||
ngx_module_libs="$ngx_feature_libs"
|
||||
ngx_module_order="ngx_http_range_header_filter_module\
|
||||
ngx_pagespeed_etag_filter\
|
||||
ngx_http_gzip_filter_module \
|
||||
ngx_http_brotli_filter_module \
|
||||
ngx_pagespeed \
|
||||
ngx_http_postpone_filter_module \
|
||||
ngx_http_ssi_filter_module \
|
||||
ngx_http_charset_filter_module \
|
||||
ngx_http_xslt_filter_module \
|
||||
ngx_http_image_filter_module \
|
||||
ngx_http_sub_filter_module \
|
||||
ngx_http_addition_filter_module \
|
||||
ngx_http_gunzip_filter_module \
|
||||
ngx_http_userid_filter_module \
|
||||
ngx_http_headers_filter_module"
|
||||
|
||||
. auto/module
|
||||
|
||||
if [ $ngx_module_link != DYNAMIC ]; then
|
||||
# ngx_module_order doesn't work with static modules,
|
||||
# so we must re-order filters here.
|
||||
if [ "$position_aux" = "true" ] ; then
|
||||
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES $ngx_addon_name"
|
||||
else
|
||||
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES \
|
||||
| sed "s/ngx_pagespeed//" \
|
||||
| sed "s/$next/$next ngx_pagespeed/")
|
||||
fi
|
||||
# Make the etag header filter run immediately before range header filter.
|
||||
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES \
|
||||
| sed "s/ngx_pagespeed_etag_filter//" \
|
||||
| sed "s/ngx_http_range_header_filter_module/ngx_http_range_header_filter_module ngx_pagespeed_etag_filter/")
|
||||
else
|
||||
# config.make is not executed for dynamic modules
|
||||
CFLAGS="$CFLAGS -Wno-c++11-extensions"
|
||||
if [ "$position_aux" = "true" ] ; then
|
||||
ngx_module_type=HTTP_AUX_FILTER
|
||||
ngx_module_order=""
|
||||
fi
|
||||
fi
|
||||
else
|
||||
CORE_LIBS="$CORE_LIBS $pagespeed_libs"
|
||||
CORE_INCS="$CORE_INCS $pagespeed_include"
|
||||
NGX_ADDON_SRCS="$PS_NGX_SRCS"
|
||||
if [ "$position_aux" = "true" ] ; then
|
||||
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES $ngx_addon_name"
|
||||
else
|
||||
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES | sed "s/$next/$next $ngx_addon_name/")
|
||||
fi
|
||||
|
||||
# Make the etag header filter run immediately before range header filter.
|
||||
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES |\
|
||||
sed "s/ngx_http_range_header_filter_module/ngx_http_range_header_filter_module ngx_pagespeed_etag_filter/")
|
||||
fi
|
||||
|
||||
echo "List of modules (in reverse order of applicability): "$HTTP_FILTER_MODULES
|
||||
|
||||
# Test whether the compiler is compatible
|
||||
ngx_feature="psol-compiler-compat"
|
||||
ngx_feature_name=""
|
||||
|
||||
+31
-5
@@ -118,6 +118,8 @@ const char* BaseFetchTypeToCStr(NgxBaseFetchType type) {
|
||||
return "can't get here";
|
||||
}
|
||||
|
||||
// TODO(oschaaf): replace the ngx_log_error with VLOGS or pass in a
|
||||
// MessageHandler and use that.
|
||||
void NgxBaseFetch::ReadCallback(const ps_event_data& data) {
|
||||
NgxBaseFetch* base_fetch = reinterpret_cast<NgxBaseFetch*>(data.sender);
|
||||
ngx_http_request_t* r = base_fetch->request();
|
||||
@@ -138,19 +140,40 @@ void NgxBaseFetch::ReadCallback(const ps_event_data& data) {
|
||||
if (refcount == 0 || detached) {
|
||||
return;
|
||||
}
|
||||
|
||||
ps_request_ctx_t* ctx = ps_get_request_context(r);
|
||||
|
||||
CHECK(data.sender == ctx->base_fetch);
|
||||
CHECK(r->count > 0) << "r->count: " << r->count;
|
||||
// If our request context was zeroed, skip this event.
|
||||
// See https://github.com/pagespeed/ngx_pagespeed/issues/1081
|
||||
if (ctx == NULL) {
|
||||
// Should not happen normally, when it does this message will cause our
|
||||
// system tests to fail.
|
||||
ngx_log_error(NGX_LOG_WARN, ngx_cycle->log, 0,
|
||||
"pagespeed [%p] skipping event: request context gone", r);
|
||||
return;
|
||||
}
|
||||
|
||||
// Normally we expect the sender to equal the active NgxBaseFetch instance.
|
||||
DCHECK(data.sender == ctx->base_fetch);
|
||||
|
||||
// If someone changed our request context or NgxBaseFetch, skip processing.
|
||||
if (data.sender != ctx->base_fetch) {
|
||||
ngx_log_error(NGX_LOG_WARN, ngx_cycle->log, 0,
|
||||
"pagespeed [%p] skipping event: event originating from disassociated"
|
||||
" NgxBaseFetch instance.", r);
|
||||
return;
|
||||
}
|
||||
|
||||
int rc;
|
||||
bool run_posted = true;
|
||||
// If we are unlucky enough to have our connection finalized mid-ipro-lookup,
|
||||
// we must enter a different flow. Also see ps_in_place_check_header_filter().
|
||||
if ((ctx->base_fetch->base_fetch_type_ != kIproLookup)
|
||||
&& r->connection->error) {
|
||||
ngx_log_error(NGX_LOG_DEBUG, ngx_cycle->log, 0,
|
||||
"pagespeed [%p] request already finalized", r);
|
||||
"pagespeed [%p] request already finalized %d", r, r->count);
|
||||
rc = NGX_ERROR;
|
||||
run_posted = false;
|
||||
} else {
|
||||
rc = ps_base_fetch::ps_base_fetch_handler(r);
|
||||
}
|
||||
@@ -163,8 +186,11 @@ void NgxBaseFetch::ReadCallback(const ps_event_data& data) {
|
||||
|
||||
ngx_connection_t* c = r->connection;
|
||||
ngx_http_finalize_request(r, rc);
|
||||
// See http://forum.nginx.org/read.php?2,253006,253061
|
||||
ngx_http_run_posted_requests(c);
|
||||
|
||||
if (run_posted) {
|
||||
// See http://forum.nginx.org/read.php?2,253006,253061
|
||||
ngx_http_run_posted_requests(c);
|
||||
}
|
||||
}
|
||||
|
||||
void NgxBaseFetch::Lock() {
|
||||
|
||||
+5
-3
@@ -315,7 +315,9 @@ bool NgxFetch::Init() {
|
||||
}
|
||||
|
||||
if (!ParseUrl()) {
|
||||
message_handler_->Message(kError, "NgxFetch: ParseUrl() failed");
|
||||
message_handler_->Message(kError,
|
||||
"NgxFetch: ParseUrl() failed for [%s]:%s",
|
||||
str_url_.c_str(), url_.err);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -938,8 +940,8 @@ void NgxFetch::FixUserAgent() {
|
||||
user_agent += "NgxNativeFetcher";
|
||||
}
|
||||
GoogleString version = StrCat(
|
||||
" ", kModPagespeedSubrequestUserAgent,
|
||||
"/" MOD_PAGESPEED_VERSION_STRING "-" LASTCHANGE_STRING);
|
||||
" (", kModPagespeedSubrequestUserAgent,
|
||||
"/" MOD_PAGESPEED_VERSION_STRING "-" LASTCHANGE_STRING ")");
|
||||
if (!StringPiece(user_agent).ends_with(version)) {
|
||||
user_agent += version;
|
||||
}
|
||||
|
||||
+52
-29
@@ -284,7 +284,8 @@ ngx_int_t ps_base_fetch_handler(ngx_http_request_t* r) {
|
||||
// modules running after us to manipulate those responses.
|
||||
if (!status_ok && (ctx->base_fetch->base_fetch_type() != kHtmlTransform
|
||||
&& ctx->base_fetch->base_fetch_type() != kIproLookup)) {
|
||||
return status_code;
|
||||
ps_release_base_fetch(ctx);
|
||||
return ngx_http_filter_finalize_request(r, NULL, status_code);
|
||||
}
|
||||
|
||||
if (ctx->preserve_caching_headers != kDontPreserveHeaders) {
|
||||
@@ -302,6 +303,12 @@ ngx_int_t ps_base_fetch_handler(ngx_http_request_t* r) {
|
||||
STR_CASE_EQ_LITERAL(header->key, "Last-Modified") ||
|
||||
STR_CASE_EQ_LITERAL(header->key, "Expires"))))) {
|
||||
header->hash = 0;
|
||||
if (STR_CASE_EQ_LITERAL(header->key, "Location")) {
|
||||
// There's a possible issue with the location header, where setting
|
||||
// the hash to 0 is not enough. See:
|
||||
// https://github.com/nginx/nginx/blob/master/src/http/ngx_http_header_filter_module.c#L314
|
||||
r->headers_out.location = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -452,11 +459,6 @@ void copy_response_headers_from_ngx(const ngx_http_request_t* r,
|
||||
|
||||
headers->set_status_code(r->headers_out.status);
|
||||
|
||||
if (r->headers_out.location != NULL) {
|
||||
headers->Add(HttpAttributes::kLocation,
|
||||
str_to_string_piece(r->headers_out.location->value));
|
||||
}
|
||||
|
||||
// Manually copy over the content type because it's not included in
|
||||
// request_->headers_out.headers.
|
||||
headers->Add(HttpAttributes::kContentType,
|
||||
@@ -490,6 +492,10 @@ ngx_int_t copy_response_headers_to_ngx(
|
||||
|
||||
ngx_int_t i;
|
||||
for (i = 0 ; i < pagespeed_headers.NumAttributes() ; i++) {
|
||||
// For IPRO cache misses, these gs_ variables may point to freed memory
|
||||
// when nginx writes the headers to the output as the NgxBaseFetch instance
|
||||
// that owns this memory gets released during request processing. So we
|
||||
// copy these strings later on.
|
||||
const GoogleString& name_gs = pagespeed_headers.Name(i);
|
||||
const GoogleString& value_gs = pagespeed_headers.Value(i);
|
||||
|
||||
@@ -510,6 +516,9 @@ ngx_int_t copy_response_headers_to_ngx(
|
||||
} // else we don't preserve any headers.
|
||||
|
||||
ngx_str_t name, value;
|
||||
value.len = value_gs.size();
|
||||
value.data = reinterpret_cast<u_char*>(
|
||||
string_piece_to_pool_string(r->pool, value_gs.c_str()));
|
||||
|
||||
// To prevent the gzip module from clearing weak etags, we output them
|
||||
// using a different name here. The etag header filter module runs behind
|
||||
@@ -520,11 +529,15 @@ ngx_int_t copy_response_headers_to_ngx(
|
||||
name.data = reinterpret_cast<u_char*>(
|
||||
const_cast<char*>(kInternalEtagName));
|
||||
} else {
|
||||
name.len = name_gs.length();
|
||||
name.data = reinterpret_cast<u_char*>(const_cast<char*>(name_gs.data()));
|
||||
name.len = name_gs.size();
|
||||
name.data = reinterpret_cast<u_char*>(
|
||||
string_piece_to_pool_string(r->pool, name_gs.c_str()));
|
||||
}
|
||||
|
||||
// In case string_piece_to_pool_string failed:
|
||||
if (name.data == NULL || value.data == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
value.len = value_gs.length();
|
||||
value.data = reinterpret_cast<u_char*>(const_cast<char*>(value_gs.data()));
|
||||
|
||||
// TODO(jefftk): If we're setting a cache control header we'd like to
|
||||
// prevent any downstream code from changing it. Specifically, if we're
|
||||
@@ -535,24 +548,17 @@ ngx_int_t copy_response_headers_to_ngx(
|
||||
// net/instaweb/apache/header_util:AddResponseHeadersToRequest
|
||||
|
||||
// Make copies of name and value to put into headers_out.
|
||||
|
||||
u_char* value_s = ngx_pstrdup(r->pool, &value);
|
||||
if (value_s == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (STR_EQ_LITERAL(name, "Cache-Control")) {
|
||||
ps_set_cache_control(r, const_cast<char*>(value_gs.c_str()));
|
||||
ps_set_cache_control(r, reinterpret_cast<char*>(value.data));
|
||||
continue;
|
||||
} else if (STR_EQ_LITERAL(name, "Content-Type")) {
|
||||
// Unlike all the other headers, content_type is just a string.
|
||||
headers_out->content_type.data = value_s;
|
||||
headers_out->content_type.len = value.len;
|
||||
headers_out->content_type = value;
|
||||
|
||||
// We should not include the charset when determining content_type_len, so
|
||||
// scan for the ';' that marks the start of the charset part.
|
||||
for (ngx_uint_t i = 0; i < value.len; i++) {
|
||||
if (value_s[i] == ';') {
|
||||
if (value.data[i] == ';') {
|
||||
break;
|
||||
}
|
||||
headers_out->content_type_len = i + 1;
|
||||
@@ -570,11 +576,10 @@ ngx_int_t copy_response_headers_to_ngx(
|
||||
continue;
|
||||
} else if (STR_EQ_LITERAL(name, "Transfer-Encoding")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
u_char* name_s = ngx_pstrdup(r->pool, &name);
|
||||
if (name_s == NULL) {
|
||||
return NGX_ERROR;
|
||||
} else if (STR_EQ_LITERAL(name, "Vary") && value.len
|
||||
&& STR_EQ_LITERAL(value, "Accept-Encoding")) {
|
||||
ps_request_ctx_t* ctx = ps_get_request_context(r);
|
||||
ctx->psol_vary_accept_only = true;
|
||||
}
|
||||
|
||||
ngx_table_elt_t* header = static_cast<ngx_table_elt_t*>(
|
||||
@@ -584,10 +589,10 @@ ngx_int_t copy_response_headers_to_ngx(
|
||||
}
|
||||
|
||||
header->hash = 1; // Include this header in the output.
|
||||
header->key.data = name.data;
|
||||
header->key.len = name.len;
|
||||
header->key.data = name_s;
|
||||
header->value.data = value.data;
|
||||
header->value.len = value.len;
|
||||
header->value.data = value_s;
|
||||
|
||||
// Populate the shortcuts to commonly used headers.
|
||||
if (STR_EQ_LITERAL(name, "Date")) {
|
||||
@@ -636,7 +641,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
// If pagespeed is configured in some server block but not this one our
|
||||
// per-request code will be invoked but server context will be null. In those
|
||||
// cases we neet to short circuit, not changing anything. Currently our
|
||||
// cases we need to short circuit, not changing anything. Currently our
|
||||
// header filter, body filter, and content handler all do this, but if anyone
|
||||
// adds another way for nginx to give us a request to process we need to check
|
||||
// there as well.
|
||||
@@ -677,6 +682,13 @@ char* ps_main_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf);
|
||||
char* ps_srv_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf);
|
||||
char* ps_loc_configure(ngx_conf_t* cf, ngx_command_t* cmd, void* conf);
|
||||
|
||||
// We want NGX_CONF_MULTI for some very old versions:
|
||||
// https://github.com/pagespeed/ngx_pagespeed/commit/66f1b9aa
|
||||
// but it's gone in recent revisions, so provide a compat #define if needed
|
||||
#ifndef NGX_CONF_MULTI
|
||||
#define NGX_CONF_MULTI 0
|
||||
#endif
|
||||
|
||||
// TODO(jud): Verify that all the offsets should be NGX_HTTP_SRV_CONF_OFFSET and
|
||||
// not NGX_HTTP_LOC_CONF_OFFSET or NGX_HTTP_MAIN_CONF_OFFSET.
|
||||
ngx_command_t ps_commands[] = {
|
||||
@@ -1269,6 +1281,7 @@ ngx_int_t ps_decline_request(ngx_http_request_t* r) {
|
||||
ctx->driver->Cleanup();
|
||||
ctx->driver = NULL;
|
||||
ctx->location_field_set = false;
|
||||
ctx->psol_vary_accept_only = false;
|
||||
|
||||
// re init ctx
|
||||
ctx->html_rewrite = true;
|
||||
@@ -1839,6 +1852,7 @@ ngx_int_t ps_resource_handler(ngx_http_request_t* r,
|
||||
ctx->recorder = NULL;
|
||||
ctx->url_string = url_string;
|
||||
ctx->location_field_set = false;
|
||||
ctx->psol_vary_accept_only = false;
|
||||
|
||||
// Set up a cleanup handler on the request.
|
||||
ngx_http_cleanup_t* cleanup = ngx_http_cleanup_add(r, 0);
|
||||
@@ -2156,6 +2170,13 @@ ngx_int_t ps_etag_header_filter(ngx_http_request_t* r) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ps_request_ctx_t* ctx = ps_get_request_context(r);
|
||||
#if (NGX_HTTP_GZIP)
|
||||
if (ctx && ctx->psol_vary_accept_only) {
|
||||
r->gzip_vary = 0;
|
||||
}
|
||||
#endif
|
||||
return ngx_http_ef_next_header_filter(r);
|
||||
}
|
||||
|
||||
@@ -3066,7 +3087,9 @@ void ps_exit_child_process(ngx_cycle_t* cycle) {
|
||||
ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(
|
||||
ngx_http_cycle_get_module_main_conf(cycle, ngx_pagespeed));
|
||||
NgxBaseFetch::Terminate();
|
||||
cfg_m->driver_factory->ShutDown();
|
||||
if (cfg_m->driver_factory != NULL) {
|
||||
cfg_m->driver_factory->ShutDown();
|
||||
}
|
||||
}
|
||||
|
||||
// Called when nginx forks worker processes. No threads should be started
|
||||
|
||||
@@ -108,6 +108,7 @@ typedef struct {
|
||||
// we should mirror that when we write it back. nginx may absolutify
|
||||
// Location: headers that start with '/' without regarding X-Forwarded-Proto.
|
||||
bool location_field_set;
|
||||
bool psol_vary_accept_only;
|
||||
} ps_request_ctx_t;
|
||||
|
||||
ps_request_ctx_t* ps_get_request_context(ngx_http_request_t* r);
|
||||
|
||||
@@ -552,7 +552,7 @@ fetch_until "$URL" "fgrep -c .pagespeed." 1 --header=Host:www.google.com
|
||||
|
||||
# If this accepts the Host header and fetches from google.com it will fail with
|
||||
# a 404. Instead it should use a loopback fetch and succeed.
|
||||
URL="$HOSTNAME/mod_pagespeed_example/.pagespeed.ce.8CfGBvwDhH.css"
|
||||
URL="$HOSTNAME/mod_pagespeed_example/styles/big.css.pagespeed.ce.8CfGBvwDhH.css"
|
||||
check wget -O /dev/null --header=Host:www.google.com "$URL"
|
||||
|
||||
start_test statistics load
|
||||
@@ -1241,6 +1241,36 @@ check_from "$OUT" fgrep -qi '404'
|
||||
MATCHES=$(echo "$OUT" | grep -c "Cache-Control: override") || true
|
||||
check [ $MATCHES -eq 1 ]
|
||||
|
||||
start_test Custom 404 does not crash.
|
||||
URL=http://custom404.example.com/mod_pagespeed_test/
|
||||
URL+=A.doesnotexist.css.pagespeed.cf.0.css
|
||||
# The 404 response makes wget exit with an error code, which we ignore.
|
||||
OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1) || true
|
||||
# We ignored the exit code, check if we got a 404 response.
|
||||
check_from "$OUT" fgrep -qi '404'
|
||||
|
||||
if false; then
|
||||
# This test fails on 1.11, but passes on trunk. While 2b4c097 fixed most users,
|
||||
# it's still possible to get two Vary: Accept-Encoding headers in this test, so
|
||||
# disable it for now.
|
||||
start_test Single Vary: Accept-Encoding header in IPRO flow
|
||||
URL=http://psol-vary.example.com/mod_pagespeed_example/styles/index_style.css
|
||||
OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1)
|
||||
# First hit will be recorded and passed on untouched
|
||||
MATCHES=$(echo "$OUT" | grep -c "Vary: Accept-Encoding") || true
|
||||
check [ $MATCHES -eq 1 ]
|
||||
|
||||
# Fetch until we get a fully optimized response
|
||||
http_proxy=$SECONDARY_HOSTNAME \
|
||||
fetch_until $URL "fgrep -c W/\"PSA" 1 --save-headers
|
||||
|
||||
# Test the optimized response.
|
||||
OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1)
|
||||
MATCHES=$(echo "$OUT" | grep -c "Vary: Accept-Encoding") || true
|
||||
check [ $MATCHES -eq 1 ]
|
||||
|
||||
fi
|
||||
|
||||
start_test Shutting down.
|
||||
|
||||
# Fire up some heavy load if ab is available to test a stressed shutdown
|
||||
@@ -1316,6 +1346,8 @@ OUT=$(cat "$ERROR_LOG" \
|
||||
| grep -v "\\[warn\\].*remote\.cfg.*" \
|
||||
| grep -v "\\[warn\\].*end token not received.*" \
|
||||
| grep -v "\\[warn\\].*failed to hook next event.*" \
|
||||
| grep -v "\\[warn\\].*Rewrite.*failed.*.pagespeed....0.foo.*" \
|
||||
| grep -v "\\[warn\\].*A.blue.css.*but cannot access the original.*" \
|
||||
|| true)
|
||||
|
||||
check [ -z "$OUT" ]
|
||||
|
||||
@@ -703,7 +703,44 @@ http {
|
||||
pagespeed EnableFilters rewrite_images,rewrite_css;
|
||||
pagespeed EnableFilters convert_to_webp_lossless;
|
||||
pagespeed EnableFilters in_place_optimize_for_browser;
|
||||
pagespeed JpegRecompressionQuality 75;
|
||||
pagespeed WebpRecompressionQuality 70;
|
||||
pagespeed InPlaceResourceOptimization on;
|
||||
pagespeed AllowVaryOn "Accept";
|
||||
pagespeed FileCachePath "@@IPRO_CACHE@@";
|
||||
}
|
||||
|
||||
server {
|
||||
listen @@SECONDARY_PORT@@;
|
||||
listen [::]:@@SECONDARY_PORT@@;
|
||||
server_name ipro-for-browser-vary-on-auto.example.com;
|
||||
root "@@SERVER_ROOT@@/mod_pagespeed_example";
|
||||
pagespeed EnableFilters rewrite_images,rewrite_css;
|
||||
pagespeed EnableFilters convert_to_webp_animated;
|
||||
pagespeed EnableFilters convert_to_webp_lossless;
|
||||
pagespeed EnableFilters in_place_optimize_for_browser;
|
||||
pagespeed InPlaceResourceOptimization on;
|
||||
# pagespeed AllowVaryOn "Accept"; # Default is "Auto".
|
||||
pagespeed ImageRecompressionQuality 90;
|
||||
pagespeed JpegRecompressionQuality 75;
|
||||
pagespeed JpegRecompressionQualityForSmallScreens 55;
|
||||
pagespeed JpegQualityForSaveData 35;
|
||||
pagespeed WebpRecompressionQuality 70;
|
||||
pagespeed WebpRecompressionQualityForSmallScreens 50;
|
||||
pagespeed WebpQualityForSaveData 30;
|
||||
pagespeed WebpAnimatedRecompressionQuality 60;
|
||||
pagespeed FileCachePath "@@IPRO_CACHE@@";
|
||||
}
|
||||
|
||||
server {
|
||||
listen @@SECONDARY_PORT@@;
|
||||
listen [::]:@@SECONDARY_PORT@@;
|
||||
server_name ipro-for-browser-vary-on-none.example.com;
|
||||
root "@@SERVER_ROOT@@/mod_pagespeed_example";
|
||||
pagespeed EnableFilters rewrite_images,in_place_optimize_for_browser;
|
||||
pagespeed InPlaceResourceOptimization on;
|
||||
pagespeed AllowVaryOn "None";
|
||||
pagespeed ImageRecompressionQuality 75;
|
||||
pagespeed FileCachePath "@@IPRO_CACHE@@";
|
||||
}
|
||||
|
||||
@@ -967,6 +1004,14 @@ http {
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen @@SECONDARY_PORT@@;
|
||||
listen [::]:@@SECONDARY_PORT@@;
|
||||
server_name custom404.example.com;
|
||||
pagespeed FileCachePath "@@SECONDARY_CACHE@@";
|
||||
error_page 404 /404.html;
|
||||
}
|
||||
|
||||
server {
|
||||
listen @@SECONDARY_PORT@@;
|
||||
listen [::]:@@SECONDARY_PORT@@;
|
||||
@@ -1463,6 +1508,14 @@ http {
|
||||
pagespeed GlobalAdminDomains
|
||||
Allow everything-explicitly-allowed.example.com;
|
||||
}
|
||||
server {
|
||||
listen @@SECONDARY_PORT@@;
|
||||
listen [::]:@@SECONDARY_PORT@@;
|
||||
server_name psol-vary.example.com;
|
||||
pagespeed on;
|
||||
pagespeed InPlaceResourceOptimization on;
|
||||
pagespeed FileCachePath "@@FILE_CACHE@@";
|
||||
}
|
||||
|
||||
server {
|
||||
listen @@PRIMARY_PORT@@;
|
||||
@@ -1748,6 +1801,25 @@ http {
|
||||
https://www.gstatic.com/psa/static;
|
||||
}
|
||||
|
||||
location /mod_pagespeed_test/strip_subresource_hints/default/ {
|
||||
pagespeed DisableFilters add_instrumentation;
|
||||
pagespeed RewriteLevel CoreFilters;
|
||||
pagespeed DisAllow *dontrewriteme*;
|
||||
}
|
||||
location /mod_pagespeed_test/strip_subresource_hints/default_passthrough/ {
|
||||
pagespeed DisableFilters add_instrumentation;
|
||||
pagespeed RewriteLevel PassThrough;
|
||||
}
|
||||
location /mod_pagespeed_test/strip_subresource_hints/preserve_on/ {
|
||||
pagespeed DisableFilters add_instrumentation;
|
||||
pagespeed PreserveSubresourceHints on;
|
||||
pagespeed RewriteLevel CoreFilters;
|
||||
}
|
||||
location /mod_pagespeed_test/strip_subresource_hints/preserve_off/ {
|
||||
pagespeed DisableFilters add_instrumentation;
|
||||
pagespeed PreserveSubresourceHints off;
|
||||
pagespeed RewriteLevel CoreFilters;
|
||||
}
|
||||
# $host implicitly tests script variable support. I'd love to test it more
|
||||
# directly, but so far this is the best I've come up with and duplicating
|
||||
# the test doesn't seem to make sense.
|
||||
|
||||
+4
-2
@@ -23,9 +23,11 @@
|
||||
# Exits with status 2 if command line args are wrong.
|
||||
#
|
||||
# Usage:
|
||||
# ./run_tests.sh primary_port secondary_port mod_pagespeed_dir pagespeed_test_host
|
||||
# ./run_tests.sh primary_port secondary_port mod_pagespeed_dir ngx_binary
|
||||
# pagespeed_test_host
|
||||
# Example:
|
||||
# ./run_tests.sh 8050 8051 /path/to/mod_pagespeed www.modpagespeed.com
|
||||
# ./run_tests.sh 8050 8051 /path/to/mod_pagespeed /path/to/nginx/binary
|
||||
# selfsigned.modpagespeed.com
|
||||
#
|
||||
|
||||
# Normally we test only with the native fetcher off. Set
|
||||
|
||||
Reference in New Issue
Block a user