Compare commits

...

2 Commits

Author SHA1 Message Date
Maks Orlovich cdbe0eb97d Port to handlers.h removal (r3816) 2014-03-03 10:59:53 -05:00
Maks Orlovich 16d40c2430 Port tests with r3812 2014-03-03 10:56:13 -05:00
3 changed files with 116 additions and 12 deletions
+13 -11
View File
@@ -50,11 +50,11 @@
#include "net/instaweb/rewriter/public/rewrite_options.h"
#include "net/instaweb/rewriter/public/rewrite_stats.h"
#include "net/instaweb/rewriter/public/static_asset_manager.h"
#include "net/instaweb/system/public/handlers.h"
#include "net/instaweb/system/public/in_place_resource_recorder.h"
#include "net/instaweb/system/public/system_caches.h"
#include "net/instaweb/system/public/system_request_context.h"
#include "net/instaweb/system/public/system_rewrite_options.h"
#include "net/instaweb/system/public/system_server_context.h"
#include "net/instaweb/system/public/system_thread_system.h"
#include "net/instaweb/util/public/fallback_property_page.h"
#include "net/instaweb/util/public/google_message_handler.h"
@@ -2286,21 +2286,23 @@ ngx_int_t ps_simple_handler(ngx_http_request_t* r,
file_contents.CopyToString(&output);
break;
}
case RequestRouting::kStatistics:
error_message = StatisticsHandler(
factory,
server_context,
case RequestRouting::kStatistics: {
bool is_global_request =
!factory->use_per_vhost_statistics() ||
StringCaseStartsWith(
request_uri_path, "/ngx_pagespeed_global_statistics");
error_message = server_context->StatisticsHandler(
factory->caches(),
is_global_request ?
factory->statistics() : server_context->statistics(),
NULL, // No SPDY-specific config in ngx_pagespeed.
!factory->use_per_vhost_statistics() || StringCaseStartsWith(
request_uri_path, "/ngx_pagespeed_global_statistics"),
StringPiece(reinterpret_cast<char*>(r->args.data), r->args.len),
&content_type,
&writer,
message_handler);
&writer);
break;
}
case RequestRouting::kConsole:
ConsoleHandler(
server_context, server_context->config(), &writer, message_handler);
server_context->ConsoleHandler(server_context->config(), &writer);
break;
case RequestRouting::kMessages: {
GoogleString log;
+71
View File
@@ -433,6 +433,61 @@ if [ "$HOSTNAME" = "localhost:$PRIMARY_PORT" ] ; then
wget -O - --header="Host: $HOSTNAME" $ALT_CE_URL >& "$TEMPDIR/alt_ce_url.$$"
check [ $? = 8 ]
rm -f "$TEMPDIR/alt_ce_url.$$"
# Even though we don't have a cookie, we will conservatively avoid
# optimizing resources with Vary:Cookie set on the response, so we
# will not get the instant response, of "body{background:#9370db}":
# 24 bytes, but will get the full original text:
# "body {\n background: MediumPurple;\n}\n"
# This will happen whether or not we send a cookie.
#
# Testing this requires proving we'll never optimize something, which
# can't be distinguished from the not-yet-optimized case, except by the
# ipro_not_rewritable stat, so we loop by scraping that stat and seeing
# when it changes.
# Executes commands until ipro_no_rewrite_count changes. The
# command-line options are all passed to WGET_DUMP. Leaves command
# wget output in $IPRO_OUTPUT.
function ipro_expect_no_rewrite() {
ipro_no_rewrite_count_start=$(scrape_stat ipro_not_rewritable)
ipro_no_rewrite_count=$ipro_no_rewrite_count_start
iters=0
while [ $ipro_no_rewrite_count -eq $ipro_no_rewrite_count_start ]; do
if [ $iters -ne 0 ]; then
sleep 0.1
if [ $iters -gt 100 ]; then
echo TIMEOUT
exit 1
fi
fi
IPRO_OUTPUT=$($WGET_DUMP "$@")
ipro_no_rewrite_count=$(scrape_stat ipro_not_rewritable)
iters=$((iters + 1))
done
}
start_test ipro with vary:cookie with no cookie set
ipro_expect_no_rewrite $TEST_ROOT/ipro/cookie/vary_cookie.css
check_from "$IPRO_OUTPUT" fgrep -q ' background: MediumPurple;'
check_from "$IPRO_OUTPUT" fgrep -q 'Vary: Cookie'
start_test ipro with vary:cookie with cookie set
ipro_expect_no_rewrite $TEST_ROOT/ipro/cookie/vary_cookie.css \
--header=Cookie:cookie-data
check_from "$IPRO_OUTPUT" fgrep -q ' background: MediumPurple;'
check_from "$IPRO_OUTPUT" fgrep -q 'Vary: Cookie'
start_test ipro with vary:cookie2 with no cookie2 set
ipro_expect_no_rewrite $TEST_ROOT/ipro/cookie2/vary_cookie2.css
check_from "$IPRO_OUTPUT" fgrep -q ' background: MediumPurple;'
check_from "$IPRO_OUTPUT" fgrep -q 'Vary: Cookie2'
start_test ipro with vary:cookie2 with cookie2 set
ipro_expect_no_rewrite $TEST_ROOT/ipro/cookie2/vary_cookie2.css \
--header=Cookie2:cookie2-data
check_from "$IPRO_OUTPUT" fgrep -q ' background: MediumPurple;'
check_from "$IPRO_OUTPUT" fgrep -q 'Vary: Cookie2'
fi
start_test Accept bad query params and headers
@@ -450,6 +505,22 @@ check_from "$OUT" grep "$EXPECTED_EXAMPLES_TEXT"
OUT=$(wget -O - --header=PageSpeedFilters:bogus $EXAMPLE_ROOT)
check_from "$OUT" grep "$EXPECTED_EXAMPLES_TEXT"
# Tests that an origin header with a Vary header other than Vary:Accept-Encoding
# loses that header when we are not respecting vary.
start_test Vary:User-Agent on resources is held by our cache.
URL="$TEST_ROOT/vary/no_respect/index.html"
fetch_until -save $URL 'grep -c \.pagespeed\.cf\.' 1
# Extract out the rewritten CSS file from the HTML saved by fetch_until
# above (see -save and definition of fetch_until). Fetch that CSS
# file with headers and make sure the Vary is stripped.
CSS_URL=$(grep stylesheet $FETCH_UNTIL_OUTFILE | cut -d\" -f 4)
CSS_URL="$TEST_ROOT/vary/no_respect/$(basename $CSS_URL)"
echo CSS_URL=$CSS_URL
CSS_OUT=$($WGET_DUMP $CSS_URL)
check_from "$CSS_OUT" fgrep -q "Vary: Accept-Encoding"
check_not_from "$CSS_OUT" fgrep -q "User-Agent"
# Test that loopback route fetcher works with vhosts not listening on
# 127.0.0.1
start_test IP choice for loopback fetches.
+31
View File
@@ -963,6 +963,37 @@ http {
pagespeed InPlaceRewriteDeadlineMs -1;
}
location /mod_pagespeed_test/ipro/cookie/ {
# Add Vary:Cookie. This should prevent us from optimizing the
# vary_cookie.css even though PagespeedRespectVary is off.
# test/nginx_system_test.sh does the fetches test with and w/o cookies.
add_header Vary Cookie;
pagespeed RespectVary off;
pagespeed InPlaceWaitForOptimized on;
}
location /mod_pagespeed_test/ipro/cookie2/ {
# Add Vary:Cookie2. This should prevent us from optimizing the
# vary_cookie2.css even though PagespeedRespectVary is off.
# test/nginx_system_test.sh does the fetches test with and w/o cookie2.
add_header Vary Cookie2;
pagespeed RespectVary off;
pagespeed InPlaceWaitForOptimized on;
}
location /mod_pagespeed_test/vary/ {
pagespeed RespectVary on;
}
location ~ /mod_pagespeed_test/vary/\.(js|css)$ {
add_header Vary User-Agent;
}
location /mod_pagespeed_test/vary/no_respect/ {
pagespeed DisableFilters add_instrumentation,inline_css;
pagespeed RespectVary off;
}
location /mod_pagespeed_test/experimental_js_minifier/ {
pagespeed UseExperimentalJsMinifier on;
}