Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit db23c07

Browse files
keesspoelstrajeffkaufman
authored andcommitted
Strip subresource hints
Default behaviour is to strip subresource links which are in scope for pagespeed, these are the resources that are not disallowed or are valid domains in the domain laywer. Added can_modify_url flag to HtmlParse and CanModifyUrl function to the HtmlFilter which indicates whether urls can be rewritten by the parser and thus should be removed. This is tested now in the strip_subresource_hints_filter_test.cc as this is only used by the strip subresource hints feature right now. This should be moved to the HtmlParse tests. DetermineEnabledFilters has been rolled up into DetermineFiltersBehaviour, which also determines can_modify_url for all the filters and possible future "behaviors". Added new option to explicitly prevent the default behaviour: ModPreserveSubresourceHints on/off For ubuntu a check for the new setup /var/www/html instead of /var/www for the document root has been added. Fixes Issue #973. (Squash of 54983f4 and b651c78.)
1 parent a79fb28 commit db23c07

28 files changed

+655
-39
lines changed

install/debug.conf.template

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,29 @@ ModPagespeedLoadFromFile "http://@@APACHE_DOMAIN@@/mod_pagespeed_test/ipro/insta
238238
Header append 'Cache-Control' 'no-transform'
239239
</Directory>
240240

241+
<Directory "@@APACHE_DOC_ROOT@@/mod_pagespeed_test/strip_subresource_hints/default" >
242+
ModPagespeedRewriteLevel CoreFilters
243+
ModPagespeedDisableFilters add_instrumentation
244+
ModPagespeedDisallow *dontrewriteme*
245+
</Directory>
246+
247+
<Directory "@@APACHE_DOC_ROOT@@/mod_pagespeed_test/strip_subresource_hints/preserve_on/" >
248+
ModPagespeedPreserveSubresourceHints on
249+
ModPagespeedRewriteLevel CoreFilters
250+
ModPagespeedDisableFilters add_instrumentation
251+
</Directory>
252+
253+
<Directory "@@APACHE_DOC_ROOT@@/mod_pagespeed_test/strip_subresource_hints/preserve_off/" >
254+
ModPagespeedPreserveSubresourceHints off
255+
ModPagespeedRewriteLevel CoreFilters
256+
ModPagespeedDisableFilters add_instrumentation
257+
</Directory>
258+
259+
<Directory "@@APACHE_DOC_ROOT@@/mod_pagespeed_test/strip_subresource_hints/default_passthrough/" >
260+
ModPagespeedRewriteLevel PassThrough
261+
ModPagespeedDisableFilters add_instrumentation
262+
</Directory>
263+
241264
# This Directory does not even exist, but by setting some options in that
242265
# scope we test to make sure the options we claim are really settable in
243266
# .htaccess. Note that <Directory> and .htaccess are enforced the same way.
@@ -1912,6 +1935,7 @@ Listen 127.0.0.2:@@APACHE_TERTIARY_PORT@@
19121935
#ALL_DIRECTIVES ModPagespeedNumExpensiveRewriteThreads 2
19131936
#ALL_DIRECTIVES ModPagespeedNumRewriteThreads 4
19141937
#ALL_DIRECTIVES ModPagespeedOptionCookiesDurationMs 12345
1938+
#ALL_DIRECTIVES ModPagespeedPreserveSubresourceHints on
19151939
#ALL_DIRECTIVES ModPagespeedPreserveUrlRelativity on
19161940
#ALL_DIRECTIVES ModPagespeedProgressiveJpegMinBytes 1000
19171941
#ALL_DIRECTIVES ModPagespeedRateLimitBackgroundFetches true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<head><link rel="subresource" src="dontrewriteme_resource.jpg"/></head>
3+
<body>
4+
</body>
5+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<head><link rel="subresource" src="test"/></head>
3+
<body>
4+
</body>
5+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<link rel="subresource" src="test1"/>
4+
<link rel="subresource" src="test2"/>
5+
</head>
6+
<body>
7+
</body>
8+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<head><link rel="subresource" src="test"/></head>
3+
<body>
4+
</body>
5+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<head><link rel="subresource" src="test"/></head>
3+
<body>
4+
</body>
5+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<head><link rel="subresource" src="test"/></head>
3+
<body>
4+
</body>
5+
</html>

install/setup_test_machine.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ fi
6666
# This sequence is described in /usr/share/doc/apache2.2-common/README.Debian.gz
6767
sudo a2ensite default-ssl
6868
sudo a2enmod ssl
69+
sudo a2enmod headers
6970
sudo make-ssl-cert generate-default-snakeoil --force-overwrite
7071

7172
# TODO(jefftk): We don't restart the test servers often enough for this to be

install/ubuntu.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22

33
echo make $*
44

5+
APACHE_DOC_ROOT=/var/www
6+
# Test for new ubuntu setups where doc/root is in /var/www/html. We could run
7+
# into a false positive here, but probably not for build systems.
8+
if [ -e /var/www/html ]; then
9+
APACHE_DOC_ROOT=/var/www/html
10+
fi
11+
512
exec make \
613
APACHE_CONTROL_PROGRAM=/etc/init.d/apache2 \
714
APACHE_LOG=/var/log/apache2/error.log \
815
APACHE_MODULES=/usr/lib/apache2/modules \
916
APACHE_CONF_FILE=/etc/apache2/apache2.conf \
17+
APACHE_DOC_ROOT=$APACHE_DOC_ROOT \
1018
APACHE_PIDFILE=/var/run/apache2.pid \
1119
APACHE_PROGRAM=/usr/sbin/apache2 \
1220
APACHE_ROOT=/etc/apache2 \

net/instaweb/instaweb.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,7 @@
18321832
'rewriter/split_html_helper_filter.cc',
18331833
'rewriter/strip_non_cacheable_filter.cc',
18341834
'rewriter/strip_scripts_filter.cc',
1835+
'rewriter/strip_subresource_hints_filter.cc',
18351836
'rewriter/support_noscript_filter.cc',
18361837
'rewriter/suppress_prehead_filter.cc',
18371838
'rewriter/url_input_resource.cc',

0 commit comments

Comments
 (0)