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

Commit a49af6b

Browse files
committed
turn off rewriting of X-Sendfile and X-Accel-Redirect files
1 parent c8c304a commit a49af6b

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

install/debug.conf.template

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,32 @@ NameVirtualHost localhost:@@APACHE_SECONDARY_PORT@@
763763
ModPagespeedDisableFilters remove_comments,add_instrumentation
764764
</VirtualHost>
765765

766+
<VirtualHost localhost:@@APACHE_SECONDARY_PORT@@>
767+
ServerName uses-sendfile.example.com
768+
ModPagespeedBlockingRewriteKey psatest
769+
DocumentRoot "@@APACHE_DOC_ROOT@@"
770+
ModPagespeedFileCachePath "@@MOD_PAGESPEED_CACHE@@"
771+
ModPagespeedEnableFilters rewrite_javascript
772+
Header always set X-Sendfile blablabla
773+
</VirtualHost>
774+
775+
<VirtualHost localhost:@@APACHE_SECONDARY_PORT@@>
776+
ServerName uses-xaccelredirect.example.com
777+
ModPagespeedBlockingRewriteKey psatest
778+
DocumentRoot "@@APACHE_DOC_ROOT@@"
779+
ModPagespeedFileCachePath "@@MOD_PAGESPEED_CACHE@@"
780+
ModPagespeedEnableFilters rewrite_javascript
781+
Header always set X-Accel-Redirect blablabla
782+
</VirtualHost>
783+
784+
<VirtualHost localhost:@@APACHE_SECONDARY_PORT@@>
785+
ServerName doesnt-sendfile.example.com
786+
ModPagespeedBlockingRewriteKey psatest
787+
DocumentRoot "@@APACHE_DOC_ROOT@@"
788+
ModPagespeedFileCachePath "@@MOD_PAGESPEED_CACHE@@"
789+
ModPagespeedEnableFilters rewrite_javascript
790+
</VirtualHost>
791+
766792
# For testing ipro + load from file + unknown extensions.
767793
<VirtualHost localhost:@@APACHE_SECONDARY_PORT@@>
768794
ServerName lff-ipro.example.com

net/instaweb/apache/system_test.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,27 @@ start_test rewrite on Cache-control: no-transform
517517
URL=$TEST_ROOT/disable_no_transform/index.html?PageSpeedFilters=inline_css
518518
fetch_until -save -recursive $URL 'grep -c style' 2
519519

520+
# Test that we do not rewrite resources when the X-Sendfile header is set, or
521+
# when the X-Accel-Redirect header is set.
522+
start_test check that rewriting only happens without X-Sendfile
523+
function verify_no_rewriting_sendfile() {
524+
local sendfile_hostname=$1
525+
local sendfile_header=$2
526+
URL="http://${sendfile_hostname}.example.com/mod_pagespeed_test/normal.js"
527+
OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP \
528+
--header 'X-PSA-Blocking-Rewrite: psatest' --save-headers $URL)
529+
check_from "$OUT" grep $sendfile_header
530+
check_from "$OUT" grep comment2
531+
}
532+
verify_no_rewriting_sendfile "uses-sendfile" "X-Sendfile"
533+
verify_no_rewriting_sendfile "uses-xaccelredirect" "X-Accel-Redirect"
534+
# doesnt-sendfile.example.com has identical configuration, but just does not
535+
# set the X-Sendfile header. Check this here to make sure that we have do
536+
# rewrite under other circumstances.
537+
URL="http://doesnt-sendfile.example.com/mod_pagespeed_test/normal.js"
538+
http_proxy=$SECONDARY_HOSTNAME fetch_until -save "$URL" \
539+
'fgrep -c comment2' 0
540+
520541
start_test ModPagespeedShardDomain directive in .htaccess file
521542
test_filter extend_cache
522543
fetch_until -save $TEST_ROOT/shard/shard.html 'grep -c \.pagespeed\.' 4

net/instaweb/rewriter/resource.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ bool Resource::IsSafeToRewrite(bool rewrite_uncacheable,
126126
response_headers_.HasValue(HttpAttributes::kCacheControl,
127127
"no-transform")) {
128128
StrAppend(reason, "Cache-control: no-transform, ");
129+
} else if (response_headers_.Lookup1(HttpAttributes::kXSendfile) ||
130+
response_headers_.Lookup1(HttpAttributes::kXAccelRedirect)) {
131+
StrAppend(reason, "Sendfile in header, unsafe to rewrite! ");
129132
} else if (contents().empty()) {
130133
// https://github.com/pagespeed/mod_pagespeed/issues/1050
131134
StrAppend(reason, "Resource is empty, ");

pagespeed/kernel/http/http_names.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ const char HttpAttributes::kXSplitBelowTheFold[] = "btf";
116116
const char HttpAttributes::kXRequestedWith[] = "X-Requested-With";
117117
const char HttpAttributes::kXUACompatible[] = "X-UA-Compatible";
118118
const char HttpAttributes::kXPsaSplitConfig[] = "X-PSA-Split-Config";
119+
const char HttpAttributes::kXSendfile[] = "X-Sendfile";
120+
const char HttpAttributes::kXAccelRedirect[] = "X-Accel-Redirect";
119121

120122
const char* HttpStatus::GetReasonPhrase(HttpStatus::Code rc) {
121123
switch (rc) {

pagespeed/kernel/http/http_names.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ struct HttpAttributes {
149149
// The config to be used fo the split html xpath.
150150
static const char kXPsaSplitConfig[];
151151

152+
// Sendfile type responses.
153+
static const char kXSendfile[];
154+
static const char kXAccelRedirect[];
155+
152156
// Gets a sorted StringPieceVector containing all the hop-by-hop headers,
153157
// plus Set-Cookie and Set-Cookie2, per
154158
//

0 commit comments

Comments
 (0)