Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
turn off rewriting of X-Sendfile and X-Accel-Redirect files
Browse files Browse the repository at this point in the history
  • Loading branch information
crowell committed Jul 23, 2015
1 parent c8c304a commit a49af6b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
26 changes: 26 additions & 0 deletions install/debug.conf.template
Expand Up @@ -763,6 +763,32 @@ NameVirtualHost localhost:@@APACHE_SECONDARY_PORT@@
ModPagespeedDisableFilters remove_comments,add_instrumentation
</VirtualHost>

<VirtualHost localhost:@@APACHE_SECONDARY_PORT@@>
ServerName uses-sendfile.example.com
ModPagespeedBlockingRewriteKey psatest
DocumentRoot "@@APACHE_DOC_ROOT@@"
ModPagespeedFileCachePath "@@MOD_PAGESPEED_CACHE@@"
ModPagespeedEnableFilters rewrite_javascript
Header always set X-Sendfile blablabla
</VirtualHost>

<VirtualHost localhost:@@APACHE_SECONDARY_PORT@@>
ServerName uses-xaccelredirect.example.com
ModPagespeedBlockingRewriteKey psatest
DocumentRoot "@@APACHE_DOC_ROOT@@"
ModPagespeedFileCachePath "@@MOD_PAGESPEED_CACHE@@"
ModPagespeedEnableFilters rewrite_javascript
Header always set X-Accel-Redirect blablabla
</VirtualHost>

<VirtualHost localhost:@@APACHE_SECONDARY_PORT@@>
ServerName doesnt-sendfile.example.com
ModPagespeedBlockingRewriteKey psatest
DocumentRoot "@@APACHE_DOC_ROOT@@"
ModPagespeedFileCachePath "@@MOD_PAGESPEED_CACHE@@"
ModPagespeedEnableFilters rewrite_javascript
</VirtualHost>

# For testing ipro + load from file + unknown extensions.
<VirtualHost localhost:@@APACHE_SECONDARY_PORT@@>
ServerName lff-ipro.example.com
Expand Down
21 changes: 21 additions & 0 deletions net/instaweb/apache/system_test.sh
Expand Up @@ -517,6 +517,27 @@ start_test rewrite on Cache-control: no-transform
URL=$TEST_ROOT/disable_no_transform/index.html?PageSpeedFilters=inline_css
fetch_until -save -recursive $URL 'grep -c style' 2

# Test that we do not rewrite resources when the X-Sendfile header is set, or
# when the X-Accel-Redirect header is set.
start_test check that rewriting only happens without X-Sendfile
function verify_no_rewriting_sendfile() {
local sendfile_hostname=$1
local sendfile_header=$2
URL="http://${sendfile_hostname}.example.com/mod_pagespeed_test/normal.js"
OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP \
--header 'X-PSA-Blocking-Rewrite: psatest' --save-headers $URL)
check_from "$OUT" grep $sendfile_header
check_from "$OUT" grep comment2
}
verify_no_rewriting_sendfile "uses-sendfile" "X-Sendfile"
verify_no_rewriting_sendfile "uses-xaccelredirect" "X-Accel-Redirect"
# doesnt-sendfile.example.com has identical configuration, but just does not
# set the X-Sendfile header. Check this here to make sure that we have do
# rewrite under other circumstances.
URL="http://doesnt-sendfile.example.com/mod_pagespeed_test/normal.js"
http_proxy=$SECONDARY_HOSTNAME fetch_until -save "$URL" \
'fgrep -c comment2' 0

start_test ModPagespeedShardDomain directive in .htaccess file
test_filter extend_cache
fetch_until -save $TEST_ROOT/shard/shard.html 'grep -c \.pagespeed\.' 4
Expand Down
3 changes: 3 additions & 0 deletions net/instaweb/rewriter/resource.cc
Expand Up @@ -126,6 +126,9 @@ bool Resource::IsSafeToRewrite(bool rewrite_uncacheable,
response_headers_.HasValue(HttpAttributes::kCacheControl,
"no-transform")) {
StrAppend(reason, "Cache-control: no-transform, ");
} else if (response_headers_.Lookup1(HttpAttributes::kXSendfile) ||
response_headers_.Lookup1(HttpAttributes::kXAccelRedirect)) {
StrAppend(reason, "Sendfile in header, unsafe to rewrite! ");
} else if (contents().empty()) {
// https://github.com/pagespeed/mod_pagespeed/issues/1050
StrAppend(reason, "Resource is empty, ");
Expand Down
2 changes: 2 additions & 0 deletions pagespeed/kernel/http/http_names.cc
Expand Up @@ -116,6 +116,8 @@ const char HttpAttributes::kXSplitBelowTheFold[] = "btf";
const char HttpAttributes::kXRequestedWith[] = "X-Requested-With";
const char HttpAttributes::kXUACompatible[] = "X-UA-Compatible";
const char HttpAttributes::kXPsaSplitConfig[] = "X-PSA-Split-Config";
const char HttpAttributes::kXSendfile[] = "X-Sendfile";
const char HttpAttributes::kXAccelRedirect[] = "X-Accel-Redirect";

const char* HttpStatus::GetReasonPhrase(HttpStatus::Code rc) {
switch (rc) {
Expand Down
4 changes: 4 additions & 0 deletions pagespeed/kernel/http/http_names.h
Expand Up @@ -149,6 +149,10 @@ struct HttpAttributes {
// The config to be used fo the split html xpath.
static const char kXPsaSplitConfig[];

// Sendfile type responses.
static const char kXSendfile[];
static const char kXAccelRedirect[];

// Gets a sorted StringPieceVector containing all the hop-by-hop headers,
// plus Set-Cookie and Set-Cookie2, per
//
Expand Down

0 comments on commit a49af6b

Please sign in to comment.