trunk-tracking: port r3945 which made the location of static assets configurable

This commit is contained in:
Jeff Kaufman
2014-04-22 17:46:51 -04:00
parent 7d5fc11afd
commit b87ffce5ba
4 changed files with 8 additions and 23 deletions
+4 -4
View File
@@ -1606,8 +1606,9 @@ RequestRouting::Response ps_route_request(ngx_http_request_t* r,
if (is_pagespeed_subrequest(r)) { if (is_pagespeed_subrequest(r)) {
return RequestRouting::kPagespeedSubrequest; return RequestRouting::kPagespeedSubrequest;
} else if (url.PathSansLeaf() == } else if (
NgxRewriteDriverFactory::kStaticAssetPrefix) { url.PathSansLeaf() == dynamic_cast<NgxRewriteDriverFactory*>(
cfg_s->server_context->factory())->static_asset_prefix()) {
return RequestRouting::kStaticContent; return RequestRouting::kStaticContent;
} }
@@ -2408,8 +2409,7 @@ ngx_int_t ps_simple_handler(ngx_http_request_t* r,
case RequestRouting::kStaticContent: { case RequestRouting::kStaticContent: {
StringPiece file_contents; StringPiece file_contents;
if (!server_context->static_asset_manager()->GetAsset( if (!server_context->static_asset_manager()->GetAsset(
request_uri_path.substr( request_uri_path.substr(factory->static_asset_prefix().length()),
strlen(NgxRewriteDriverFactory::kStaticAssetPrefix)),
&file_contents, &content_type, &cache_control)) { &file_contents, &content_type, &cache_control)) {
return NGX_DECLINED; return NGX_DECLINED;
} }
-9
View File
@@ -33,7 +33,6 @@
#include "net/instaweb/rewriter/public/rewrite_driver.h" #include "net/instaweb/rewriter/public/rewrite_driver.h"
#include "net/instaweb/rewriter/public/rewrite_driver_factory.h" #include "net/instaweb/rewriter/public/rewrite_driver_factory.h"
#include "net/instaweb/rewriter/public/server_context.h" #include "net/instaweb/rewriter/public/server_context.h"
#include "net/instaweb/rewriter/public/static_asset_manager.h"
#include "net/instaweb/system/public/in_place_resource_recorder.h" #include "net/instaweb/system/public/in_place_resource_recorder.h"
#include "net/instaweb/system/public/serf_url_async_fetcher.h" #include "net/instaweb/system/public/serf_url_async_fetcher.h"
#include "net/instaweb/system/public/system_caches.h" #include "net/instaweb/system/public/system_caches.h"
@@ -63,9 +62,6 @@ class UrlAsyncFetcher;
class UrlFetcher; class UrlFetcher;
class Writer; class Writer;
const char NgxRewriteDriverFactory::kStaticAssetPrefix[] =
"/ngx_pagespeed_static/";
class SharedCircularBuffer; class SharedCircularBuffer;
NgxRewriteDriverFactory::NgxRewriteDriverFactory( NgxRewriteDriverFactory::NgxRewriteDriverFactory(
@@ -151,11 +147,6 @@ RewriteOptions* NgxRewriteDriverFactory::NewRewriteOptions() {
return options; return options;
} }
void NgxRewriteDriverFactory::InitStaticAssetManager(
StaticAssetManager* static_asset_manager) {
static_asset_manager->set_library_url_prefix(kStaticAssetPrefix);
}
bool NgxRewriteDriverFactory::InitNgxUrlAsyncFetchers() { bool NgxRewriteDriverFactory::InitNgxUrlAsyncFetchers() {
log_ = ngx_cycle->log; log_ = ngx_cycle->log;
for (size_t i = 0; i < ngx_url_async_fetchers_.size(); ++i) { for (size_t i = 0; i < ngx_url_async_fetchers_.size(); ++i) {
-6
View File
@@ -45,14 +45,11 @@ class NgxUrlAsyncFetcher;
class SharedCircularBuffer; class SharedCircularBuffer;
class SharedMemRefererStatistics; class SharedMemRefererStatistics;
class SlowWorker; class SlowWorker;
class StaticAssetManager;
class Statistics; class Statistics;
class SystemThreadSystem; class SystemThreadSystem;
class NgxRewriteDriverFactory : public SystemRewriteDriverFactory { class NgxRewriteDriverFactory : public SystemRewriteDriverFactory {
public: public:
static const char kStaticAssetPrefix[];
// We take ownership of the thread system. // We take ownership of the thread system.
explicit NgxRewriteDriverFactory( explicit NgxRewriteDriverFactory(
const ProcessContext& process_context, const ProcessContext& process_context,
@@ -68,9 +65,6 @@ class NgxRewriteDriverFactory : public SystemRewriteDriverFactory {
// Create a new RewriteOptions. In this implementation it will be an // Create a new RewriteOptions. In this implementation it will be an
// NgxRewriteOptions. // NgxRewriteOptions.
virtual RewriteOptions* NewRewriteOptions(); virtual RewriteOptions* NewRewriteOptions();
// Initializes the StaticAssetManager.
virtual void InitStaticAssetManager(
StaticAssetManager* static_asset_manager);
virtual ServerContext* NewDecodingServerContext(); virtual ServerContext* NewDecodingServerContext();
bool InitNgxUrlAsyncFetchers(); bool InitNgxUrlAsyncFetchers();
// Check resolver configured or not. // Check resolver configured or not.
+4 -4
View File
@@ -259,7 +259,7 @@ if [ ! -e "$SYSTEM_TEST_FILE" ] ; then
exit 2 exit 2
fi fi
PSA_JS_LIBRARY_URL_PREFIX="ngx_pagespeed_static" PSA_JS_LIBRARY_URL_PREFIX="pagespeed_static"
# An expected failure can be indicated like: "~In-place resource optimization~" # An expected failure can be indicated like: "~In-place resource optimization~"
PAGESPEED_EXPECTED_FAILURES=" PAGESPEED_EXPECTED_FAILURES="
@@ -2150,7 +2150,7 @@ keepalive_test "keepalive-beacon-post.example.com" "/ngx_pagespeed_beacon"\
start_test keepalive with static resources start_test keepalive with static resources
keepalive_test "keepalive-static.example.com"\ keepalive_test "keepalive-static.example.com"\
"/ngx_pagespeed_static/js_defer.0.js" "" "/pagespeed_static/js_defer.0.js" ""
# Test for MaxCombinedCssBytes. The html used in the test, 'combine_css.html', # Test for MaxCombinedCssBytes. The html used in the test, 'combine_css.html',
# has 4 CSS files in the following order. # has 4 CSS files in the following order.
@@ -2185,7 +2185,7 @@ CONNECTION=$(extract_headers $FETCH_UNTIL_OUTFILE | fgrep "Connection:")
check_not_from "$CONNECTION" fgrep -qi "Keep-Alive, Keep-Alive" check_not_from "$CONNECTION" fgrep -qi "Keep-Alive, Keep-Alive"
check_from "$CONNECTION" fgrep -qi "Keep-Alive" check_from "$CONNECTION" fgrep -qi "Keep-Alive"
start_test ngx_pagespeed_static defer js served with correct headers. start_test pagespeed_static defer js served with correct headers.
# First, determine which hash js_defer is served with. We need a correct hash # First, determine which hash js_defer is served with. We need a correct hash
# to get it served up with an Etag, which is one of the things we want to test. # to get it served up with an Etag, which is one of the things we want to test.
URL="$HOSTNAME/mod_pagespeed_example/defer_javascript.html?PageSpeed=on&PageSpeedFilters=defer_javascript" URL="$HOSTNAME/mod_pagespeed_example/defer_javascript.html?PageSpeed=on&PageSpeedFilters=defer_javascript"
@@ -2342,7 +2342,7 @@ test_decent_browsers "New Opera" \
WGETRC=$OLD_WGETRC WGETRC=$OLD_WGETRC
WGET_ARGS="" WGET_ARGS=""
JS_URL="$HOSTNAME/ngx_pagespeed_static/js_defer.$HASH.js" JS_URL="$HOSTNAME/pagespeed_static/js_defer.$HASH.js"
JS_HEADERS=$($WGET -O /dev/null -q -S --header='Accept-Encoding: gzip' \ JS_HEADERS=$($WGET -O /dev/null -q -S --header='Accept-Encoding: gzip' \
$JS_URL 2>&1) $JS_URL 2>&1)
check_from "$JS_HEADERS" egrep -qi 'HTTP/1[.]. 200 OK' check_from "$JS_HEADERS" egrep -qi 'HTTP/1[.]. 200 OK'