From b789a4574ff21b00ce11e5be83868f35c5adfe08 Mon Sep 17 00:00:00 2001 From: Jeff Kaufman Date: Thu, 4 Apr 2013 16:31:49 -0400 Subject: [PATCH] system-test: retain custom headers --- README.md | 4 +++- test/nginx_system_test.sh | 10 ++++++++++ test/pagespeed_test.conf.template | 10 ++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f1478ac379..ea0ebcda52 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,9 @@ In every server block where pagespeed is enabled add: # This is a temporary workaround that ensures requests for pagespeed # optimized resources go to the pagespeed handler. - location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { } + location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { + add_header "" ""; + } location ~ "^/ngx_pagespeed_static/" { } location ~ "^/ngx_pagespeed_beacon$" { } location /ngx_pagespeed_statistics { diff --git a/test/nginx_system_test.sh b/test/nginx_system_test.sh index 760092f3d8..5e5bc3095b 100755 --- a/test/nginx_system_test.sh +++ b/test/nginx_system_test.sh @@ -1387,4 +1387,14 @@ function check_failures_and_exit() { exit 0 } +start_test Custom headers remain on resources, but cache should be 1 year. +URL="$TEST_ROOT/compressed/hello_js.custom_ext.pagespeed.ce.HdziXmtLIV.txt" +echo $WGET_DUMP $URL +RESOURCE_HEADERS=$($WGET_DUMP $URL) +check_from "$RESOURCE_HEADERS" egrep -q 'X-Extra-Header: 1' +# The extra header should only be added once, not twice. +check_not_from "$RESOURCE_HEADERS" egrep -q 'X-Extra-Header: 1, 1' +check [ "$(echo "$RESOURCE_HEADERS" | grep -c '^X-Extra-Header: 1')" = 1 ] +check_from "$RESOURCE_HEADERS" egrep -q 'Cache-Control: max-age=31536000' + check_failures_and_exit diff --git a/test/pagespeed_test.conf.template b/test/pagespeed_test.conf.template index cefc170d96..c31ac9815a 100644 --- a/test/pagespeed_test.conf.template +++ b/test/pagespeed_test.conf.template @@ -376,6 +376,10 @@ http { server_name localhost; pagespeed FileCachePath "@@FILE_CACHE@@"; + location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { + add_header "" ""; + } + # uncomment the following two lines if you're testing memcached #pagespeed MemcachedServers "localhost:11211"; #pagespeed MemcachedThreads 1; @@ -465,6 +469,12 @@ http { location /mod_pagespeed_test/compressed/ { add_header Content-Encoding gzip; + + # Even though this is also in the server block it must be repeated here + # because add_header directives are only inherited if you don't define + # more of them. See: http://serverfault.com/questions/400197 + add_header X-Extra-Header 1; + types { text/javascript custom_ext; }