Merge pull request #997 from pagespeed/jefftk-backport-864-fix

backport #864 fix for bugfix release
diff --git a/src/ngx_pagespeed.cc b/src/ngx_pagespeed.cc
index f032595..986abe8 100644
--- a/src/ngx_pagespeed.cc
+++ b/src/ngx_pagespeed.cc
@@ -410,8 +410,6 @@
       continue;
     } else if (STR_EQ_LITERAL(name, "Transfer-Encoding")) {
       continue;
-    } else if (STR_EQ_LITERAL(name, "Server")) {
-      continue;
     }
 
     u_char* name_s = ngx_pstrdup(r->pool, &name);
diff --git a/test/nginx_system_test.sh b/test/nginx_system_test.sh
index 20cdd17..4bcb9fa 100644
--- a/test/nginx_system_test.sh
+++ b/test/nginx_system_test.sh
@@ -269,6 +269,8 @@
 
 # An expected failure can be indicated like: "~In-place resource optimization~"
 PAGESPEED_EXPECTED_FAILURES="
+~Override server header in resource flow.~
+~Override server header in IPRO flow.~
 "
 
 # Some tests are flakey under valgrind. For now, add them to the expected failures
@@ -2748,6 +2750,46 @@
 OUT=$($WGET_DUMP "$HOSTNAME/pagespeed_admin/cache?purge=*")
 check_from "$OUT" fgrep -q "pagespeed EnableCachePurge on;"
 
+start_test Default server header in html flow.
+URL=http://headers.example.com/mod_pagespeed_example/
+OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1)
+# '|| true' in the line below supresses the exit code from grep when there is no
+# match in its input (1).
+MATCHES=$(echo "$OUT" | grep -c "Server: nginx/") || true
+check [ $MATCHES -eq 1 ]
+
+start_test Default server header in resource flow.
+URL=http://headers.example.com/mod_pagespeed_example/
+URL+=combine_javascript2.js+combine_javascript1.js.pagespeed.jc.0.js
+OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1)
+MATCHES=$(echo "$OUT" | grep -c "Server: nginx/") || true
+check [ $MATCHES -eq 1 ]
+
+start_test Default server header in IPRO flow.
+URL=http://headers.example.com//mod_pagespeed_example/combine_javascript2.js
+OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1)
+MATCHES=$(echo "$OUT" | grep -c "Server: nginx/") || true
+check [ $MATCHES -eq 1 ]
+
+start_test Override server header in html flow.
+URL=http://headers.example.com/mod_pagespeed_test/whitespace.html
+OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1)
+MATCHES=$(echo "$OUT" | grep -c "Server: override") || true
+check [ $MATCHES -eq 1 ]
+
+start_test Override server header in resource flow.
+URL=http://headers.example.com/mod_pagespeed_test/
+URL+=A.proxy_pass.css.pagespeed.cf.0.css
+OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1)
+MATCHES=$(echo "$OUT" | grep -c "Server: override") || true
+check [ $MATCHES -eq 1 ]
+
+start_test Override server header in IPRO flow.
+URL=http://headers.example.com/mod_pagespeed_test/proxy_pass.css
+OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1)
+MATCHES=$(echo "$OUT" | grep -c "Server: override") || true
+check [ $MATCHES -eq 1 ]
+
 if $USE_VALGRIND; then
     # It is possible that there are still ProxyFetches outstanding
     # at this point in time. Give them a few extra seconds to allow
diff --git a/test/pagespeed_test.conf.template b/test/pagespeed_test.conf.template
index 72ef10e..c7d5e96 100644
--- a/test/pagespeed_test.conf.template
+++ b/test/pagespeed_test.conf.template
@@ -1178,6 +1178,22 @@
   }
 
   server {
+    listen @@SECONDARY_PORT@@;
+    listen [::]:@@SECONDARY_PORT@@;
+    server_name headers.example.com;
+    root "@@SERVER_ROOT@@";
+    pagespeed FileCachePath "@@FILE_CACHE@@_purge";
+    pagespeed RewriteLevel CoreFilters;
+
+    pagespeed InPlaceRewriteDeadlineMs -1;
+    pagespeed LoadFromFile "http://headers.example.com/"
+              "@@SERVER_ROOT@@/";
+    location /mod_pagespeed_test/ {
+      more_set_headers "Server: overriden";
+    }
+  }
+
+  server {
     listen @@PRIMARY_PORT@@;
     listen [::]:@@PRIMARY_PORT@@;
     server_name  localhost;