From ae2d4bac7f7b182f5228d7f71711dec8dc3a2fbc Mon Sep 17 00:00:00 2001 From: Jeff Kaufman Date: Thu, 19 Dec 2013 12:46:53 -0500 Subject: [PATCH 01/13] native-fetcher: fix to work with nginx 1.5.8+ nginx 1.5.8 changed the resolver api, which the native fetcher uses. Fixes #578. Squash-merge of @dinic's #581. --- src/ngx_fetch.cc | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ngx_fetch.cc b/src/ngx_fetch.cc index bf1bddc78..c4f8095ca 100644 --- a/src/ngx_fetch.cc +++ b/src/ngx_fetch.cc @@ -24,6 +24,10 @@ // - The read handler parses the response. Add the response to the buffer at // last. +extern "C" { +#include +} + #include "ngx_fetch.h" #include "net/instaweb/util/public/basictypes.h" #include "base/logging.h" @@ -164,7 +168,11 @@ namespace net_instaweb { resolver_ctx_->data = this; resolver_ctx_->name.data = url_.host.data; resolver_ctx_->name.len = url_.host.len; + +#if (nginx_version < 1005008) resolver_ctx_->type = NGX_RESOLVE_A; +#endif + resolver_ctx_->handler = NgxFetchResolveDone; resolver_ctx_->timeout = fetcher_->resolver_timeout_; @@ -299,9 +307,20 @@ namespace net_instaweb { return; } ngx_memzero(&fetch->sin_, sizeof(fetch->sin_)); + +#if (nginx_version < 1005008) + fetch->sin_.sin_addr.s_addr = resolver_ctx->addrs[0]; +#else + + struct sockaddr_in *sin; + sin = reinterpret_cast( + resolver_ctx->addrs[0].sockaddr); + fetch->sin_.sin_family = sin->sin_family; + fetch->sin_.sin_addr.s_addr = sin->sin_addr.s_addr; +#endif + fetch->sin_.sin_family = AF_INET; fetch->sin_.sin_port = htons(fetch->url_.port); - fetch->sin_.sin_addr.s_addr = resolver_ctx->addrs[0]; char* ip_address = inet_ntoa(fetch->sin_.sin_addr); From 72ddb34a1c40e5fc1ee9e6bb0a8f861e8f0dc4de Mon Sep 17 00:00:00 2001 From: Jeff Kaufman Date: Mon, 6 Jan 2014 16:51:41 -0500 Subject: [PATCH 02/13] readme: release 1.7.30.2 --- README.md | 20 ++++++++++---------- config | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7d66cf941..7d42caf3a 100644 --- a/README.md +++ b/README.md @@ -37,21 +37,21 @@ recompiling Tengine](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_p ```bash $ cd ~ - $ wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.7.30.1-beta.zip - $ unzip release-1.7.30.1-beta.zip # or unzip release-1.7.30.1-beta - $ cd ngx_pagespeed-release-1.7.30.1-beta/ - $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.1.tar.gz - $ tar -xzvf 1.7.30.1.tar.gz # expands to psol/ + $ wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.7.30.2-beta.zip + $ unzip v1.7.30.2-beta.zip # or unzip v1.7.30.2-beta + $ cd ngx_pagespeed-1.7.30.2-beta/ + $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.2.tar.gz + $ tar -xzvf 1.7.30.2.tar.gz # expands to psol/ ``` 3. Download and build nginx: ```bash $ # check http://nginx.org/en/download.html for the latest version - $ wget http://nginx.org/download/nginx-1.4.3.tar.gz - $ tar -xvzf nginx-1.4.3.tar.gz - $ cd nginx-1.4.3/ - $ ./configure --add-module=$HOME/ngx_pagespeed-release-1.7.30.1-beta + $ wget http://nginx.org/download/nginx-1.4.4.tar.gz + $ tar -xvzf nginx-1.4.4.tar.gz + $ cd nginx-1.4.4/ + $ ./configure --add-module=$HOME/ngx_pagespeed-1.7.30.2-beta $ make $ sudo make install ``` @@ -94,7 +94,7 @@ To confirm that the module is loaded, fetch a page and check that you see the ```bash $ curl -I 'http://localhost:8050/some_page/' | grep X-Page-Speed -X-Page-Speed: 1.7.30.1-... +X-Page-Speed: 1.7.30.2-... ``` Looking at the source of a few pages you should see various changes, such as diff --git a/config b/config index e90b6a140..1ba824811 100644 --- a/config +++ b/config @@ -27,8 +27,8 @@ if [ "$mod_pagespeed_dir" = "unset" ] ; then echo " You need to separately download the pagespeed library:" echo "" echo " $ cd /path/to/ngx_pagespeed" - echo " $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.1.tar.gz" - echo " $ tar -xzvf 1.7.30.1.tar.gz # expands to psol/" + echo " $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.2.tar.gz" + echo " $ tar -xzvf 1.7.30.2.tar.gz # expands to psol/" echo "" echo " Or see the installation instructions:" echo " https://github.com/pagespeed/ngx_pagespeed#how-to-build" From 6ccb815df36e5531e6d085576007b59486412309 Mon Sep 17 00:00:00 2001 From: tcpper Date: Thu, 16 Jan 2014 21:06:12 +0800 Subject: [PATCH 03/13] fix bug in NgxFetch#content_length_ --- src/ngx_fetch.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ngx_fetch.cc b/src/ngx_fetch.cc index e18a6502c..15dd24643 100644 --- a/src/ngx_fetch.cc +++ b/src/ngx_fetch.cc @@ -70,7 +70,7 @@ namespace net_instaweb { fetch_start_ms_(0), fetch_end_ms_(0), done_(false), - content_length_(0) { + content_length_(-1) { ngx_memzero(&url_, sizeof(url_)); log_ = log; pool_ = NULL; From 1354cee4edcb4557236da1a8ce0d3d6dad19dd9f Mon Sep 17 00:00:00 2001 From: Huibao Lin Date: Thu, 16 Jan 2014 15:06:49 -0500 Subject: [PATCH 04/13] release: prepare 1.7.30.3 --- README.md | 14 +++++++------- config | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7d42caf3a..f687c7025 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,11 @@ recompiling Tengine](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_p ```bash $ cd ~ - $ wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.7.30.2-beta.zip - $ unzip v1.7.30.2-beta.zip # or unzip v1.7.30.2-beta - $ cd ngx_pagespeed-1.7.30.2-beta/ - $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.2.tar.gz - $ tar -xzvf 1.7.30.2.tar.gz # expands to psol/ + $ wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.7.30.3-beta.zip + $ unzip v1.7.30.3-beta.zip # or unzip v1.7.30.3-beta + $ cd ngx_pagespeed-1.7.30.3-beta/ + $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.3.tar.gz + $ tar -xzvf 1.7.30.3.tar.gz # expands to psol/ ``` 3. Download and build nginx: @@ -51,7 +51,7 @@ recompiling Tengine](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_p $ wget http://nginx.org/download/nginx-1.4.4.tar.gz $ tar -xvzf nginx-1.4.4.tar.gz $ cd nginx-1.4.4/ - $ ./configure --add-module=$HOME/ngx_pagespeed-1.7.30.2-beta + $ ./configure --add-module=$HOME/ngx_pagespeed-1.7.30.3-beta $ make $ sudo make install ``` @@ -94,7 +94,7 @@ To confirm that the module is loaded, fetch a page and check that you see the ```bash $ curl -I 'http://localhost:8050/some_page/' | grep X-Page-Speed -X-Page-Speed: 1.7.30.2-... +X-Page-Speed: 1.7.30.3-... ``` Looking at the source of a few pages you should see various changes, such as diff --git a/config b/config index 1ba824811..0e958d2a0 100644 --- a/config +++ b/config @@ -27,8 +27,8 @@ if [ "$mod_pagespeed_dir" = "unset" ] ; then echo " You need to separately download the pagespeed library:" echo "" echo " $ cd /path/to/ngx_pagespeed" - echo " $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.2.tar.gz" - echo " $ tar -xzvf 1.7.30.2.tar.gz # expands to psol/" + echo " $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.3.tar.gz" + echo " $ tar -xzvf 1.7.30.3.tar.gz # expands to psol/" echo "" echo " Or see the installation instructions:" echo " https://github.com/pagespeed/ngx_pagespeed#how-to-build" From e8dd9fd3c37db6447754a6fd7da4a6f3ccd9cdb4 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sat, 15 Feb 2014 22:32:55 -0500 Subject: [PATCH 05/13] Don't call chown() when initializing config dirs unless owner != worker user. --- src/ngx_pagespeed.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ngx_pagespeed.cc b/src/ngx_pagespeed.cc index 2a2007229..8c4279c49 100644 --- a/src/ngx_pagespeed.cc +++ b/src/ngx_pagespeed.cc @@ -570,15 +570,24 @@ char* ps_init_dir(const StringPiece& directive, return NULL; // We're not root, so we're staying whoever we are. } + // chown if owner differs from nginx worker user. ngx_core_conf_t* ccf = (ngx_core_conf_t*)(ngx_get_conf(cf->cycle->conf_ctx, ngx_core_module)); CHECK(ccf != NULL); - - if (chown(gs_path.c_str(), ccf->user, ccf->group) != 0) { + struct stat gs_stat; + if (stat(gs_path.c_str(), &gs_stat) != 0) { return string_piece_to_pool_string( cf->pool, net_instaweb::StrCat( - directive, " ", path, " unable to set permissions")); + directive, " ", path, " stat() failed")); } + if (gs_stat.st_uid != ccf->user) { + if (chown(gs_path.c_str(), ccf->user, ccf->group) != 0) { + return string_piece_to_pool_string( + cf->pool, net_instaweb::StrCat( + directive, " ", path, " unable to set permissions")); + } + } + return NULL; } From c371d516a8b4495309a09a96d9749c18ba116ecc Mon Sep 17 00:00:00 2001 From: Patrick Nommensen Date: Thu, 20 Feb 2014 00:04:21 -0800 Subject: [PATCH 06/13] Update README.md nginx version update --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5b985f224..babc39b62 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,9 @@ recompiling Tengine](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_p ```bash $ cd ~ $ # check http://nginx.org/en/download.html for the latest version - $ wget http://nginx.org/download/nginx-1.4.4.tar.gz - $ tar -xvzf nginx-1.4.4.tar.gz - $ cd nginx-1.4.4/ + $ wget http://nginx.org/download/nginx-1.4.5.tar.gz + $ tar -xvzf nginx-1.4.5.tar.gz + $ cd nginx-1.4.5/ $ ./configure --add-module=$HOME/ngx_pagespeed-1.7.30.3-beta $ make $ sudo make install From 091ef6399b650261b6b0d311269dc369ac773dfb Mon Sep 17 00:00:00 2001 From: Patrick Nommensen Date: Thu, 6 Mar 2014 23:25:13 -0800 Subject: [PATCH 07/13] version update 1.4.5 to 1.4.6 http://nginx.org/en/CHANGES-1.4 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index babc39b62..c040a3b39 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,8 @@ recompiling Tengine](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_p ```bash $ cd ~ $ # check http://nginx.org/en/download.html for the latest version - $ wget http://nginx.org/download/nginx-1.4.5.tar.gz - $ tar -xvzf nginx-1.4.5.tar.gz + $ wget http://nginx.org/download/nginx-1.4.6.tar.gz + $ tar -xvzf nginx-1.4.6.tar.gz $ cd nginx-1.4.5/ $ ./configure --add-module=$HOME/ngx_pagespeed-1.7.30.3-beta $ make From 0edd405eb8cda7728d2383eb5317b1bb9ffdbe81 Mon Sep 17 00:00:00 2001 From: Patrick Nommensen Date: Fri, 7 Mar 2014 10:16:43 -0800 Subject: [PATCH 08/13] Update README.md Don't know how I missed that. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c040a3b39..9f05d124e 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ recompiling Tengine](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_p $ # check http://nginx.org/en/download.html for the latest version $ wget http://nginx.org/download/nginx-1.4.6.tar.gz $ tar -xvzf nginx-1.4.6.tar.gz - $ cd nginx-1.4.5/ + $ cd nginx-1.4.6/ $ ./configure --add-module=$HOME/ngx_pagespeed-1.7.30.3-beta $ make $ sudo make install From 497594ba7f3680937440145f4d9f6c35b76ef6bd Mon Sep 17 00:00:00 2001 From: Huibao Lin Date: Thu, 13 Mar 2014 10:18:57 -0400 Subject: [PATCH 09/13] release: build against backported change --- src/ngx_pagespeed.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ngx_pagespeed.cc b/src/ngx_pagespeed.cc index 3885ede15..d88af3388 100644 --- a/src/ngx_pagespeed.cc +++ b/src/ngx_pagespeed.cc @@ -2175,6 +2175,7 @@ ngx_int_t ps_in_place_check_header_filter(ngx_http_request_t* r) { // (or at least a note that it cannot be cached stored there). // We do that using an Apache output filter. ctx->recorder = new InPlaceResourceRecorder( + RequestContextPtr(cfg_s->server_context->NewRequestContext(r)), url, request_headers.release(), options->respect_vary(), @@ -2238,7 +2239,9 @@ ngx_int_t ps_in_place_body_filter(ngx_http_request_t* r, ngx_chain_t* in) { // Unlike in Apache we get the final response headers before we get the // content. This means we can consider them earlier and abort the // request if need be without buffering everything. - recorder->ConsiderResponseHeaders(ctx->ipro_response_headers); + recorder->ConsiderResponseHeaders( + InPlaceResourceRecorder::kPreliminaryHeaders, + ctx->ipro_response_headers); } for (ngx_chain_t* cl = in; cl; cl = cl->next) { From 86d840f76eecb814aebc46bcf399830fa3d83b56 Mon Sep 17 00:00:00 2001 From: Huibao Lin Date: Thu, 13 Mar 2014 10:27:21 -0400 Subject: [PATCH 10/13] release: udpate version number 1.7.30.3 to 1.7.30.4 --- README.md | 14 +++++++------- config | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f687c7025..6fe004557 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,11 @@ recompiling Tengine](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_p ```bash $ cd ~ - $ wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.7.30.3-beta.zip - $ unzip v1.7.30.3-beta.zip # or unzip v1.7.30.3-beta - $ cd ngx_pagespeed-1.7.30.3-beta/ - $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.3.tar.gz - $ tar -xzvf 1.7.30.3.tar.gz # expands to psol/ + $ wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.7.30.4-beta.zip + $ unzip v1.7.30.4-beta.zip # or unzip v1.7.30.4-beta + $ cd ngx_pagespeed-1.7.30.4-beta/ + $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.4.tar.gz + $ tar -xzvf 1.7.30.4.tar.gz # expands to psol/ ``` 3. Download and build nginx: @@ -51,7 +51,7 @@ recompiling Tengine](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_p $ wget http://nginx.org/download/nginx-1.4.4.tar.gz $ tar -xvzf nginx-1.4.4.tar.gz $ cd nginx-1.4.4/ - $ ./configure --add-module=$HOME/ngx_pagespeed-1.7.30.3-beta + $ ./configure --add-module=$HOME/ngx_pagespeed-1.7.30.4-beta $ make $ sudo make install ``` @@ -94,7 +94,7 @@ To confirm that the module is loaded, fetch a page and check that you see the ```bash $ curl -I 'http://localhost:8050/some_page/' | grep X-Page-Speed -X-Page-Speed: 1.7.30.3-... +X-Page-Speed: 1.7.30.4-... ``` Looking at the source of a few pages you should see various changes, such as diff --git a/config b/config index 0e958d2a0..6906807a5 100644 --- a/config +++ b/config @@ -27,8 +27,8 @@ if [ "$mod_pagespeed_dir" = "unset" ] ; then echo " You need to separately download the pagespeed library:" echo "" echo " $ cd /path/to/ngx_pagespeed" - echo " $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.3.tar.gz" - echo " $ tar -xzvf 1.7.30.3.tar.gz # expands to psol/" + echo " $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.4.tar.gz" + echo " $ tar -xzvf 1.7.30.4.tar.gz # expands to psol/" echo "" echo " Or see the installation instructions:" echo " https://github.com/pagespeed/ngx_pagespeed#how-to-build" From 707d671826fb030a26954ec780869ca69ac504ed Mon Sep 17 00:00:00 2001 From: huibaolin Date: Fri, 14 Mar 2014 08:16:38 -0400 Subject: [PATCH 11/13] Change version 1.7.30.3 to 1.7.30.4 --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9f05d124e..6f130e225 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,11 @@ recompiling Tengine](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_p ```bash $ cd ~ - $ wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.7.30.3-beta.zip - $ unzip v1.7.30.3-beta.zip # or unzip v1.7.30.3-beta - $ cd ngx_pagespeed-1.7.30.3-beta/ - $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.3.tar.gz - $ tar -xzvf 1.7.30.3.tar.gz # expands to psol/ + $ wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.7.30.4-beta.zip + $ unzip v1.7.30.4-beta.zip # or unzip v1.7.30.4-beta + $ cd ngx_pagespeed-1.7.30.4-beta/ + $ wget https://dl.google.com/dl/page-speed/psol/1.7.30.4.tar.gz + $ tar -xzvf 1.7.30.4.tar.gz # expands to psol/ ``` 3. Download and build nginx: @@ -52,7 +52,7 @@ recompiling Tengine](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_p $ wget http://nginx.org/download/nginx-1.4.6.tar.gz $ tar -xvzf nginx-1.4.6.tar.gz $ cd nginx-1.4.6/ - $ ./configure --add-module=$HOME/ngx_pagespeed-1.7.30.3-beta + $ ./configure --add-module=$HOME/ngx_pagespeed-1.7.30.4-beta $ make $ sudo make install ``` @@ -95,7 +95,7 @@ To confirm that the module is loaded, fetch a page and check that you see the ```bash $ curl -I 'http://localhost:8050/some_page/' | grep X-Page-Speed -X-Page-Speed: 1.7.30.3-... +X-Page-Speed: 1.7.30.4-... ``` Looking at the source of a few pages you should see various changes, such as From 78cf39f9b359bd4b05497aae0483edc3178e808b Mon Sep 17 00:00:00 2001 From: Jeff Kaufman Date: Wed, 19 Mar 2014 16:46:28 -0400 Subject: [PATCH 12/13] if: support pagespeed directives in location if blocks --- src/ngx_pagespeed.cc | 29 +++++++++++++++-------- test/nginx_system_test.sh | 22 +++++++++++++++++ test/pagespeed_test.conf.template | 39 +++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 10 deletions(-) diff --git a/src/ngx_pagespeed.cc b/src/ngx_pagespeed.cc index f8ef68d02..00a4d37f3 100644 --- a/src/ngx_pagespeed.cc +++ b/src/ngx_pagespeed.cc @@ -246,11 +246,11 @@ void copy_response_headers_from_ngx(const ngx_http_request_t* r, // When we don't have a date header, invent one. const char* date = headers->Lookup1(HttpAttributes::kDate); - + if (date == NULL) { headers->SetDate(ngx_current_msec); } - + // TODO(oschaaf): ComputeCaching should be called in setupforhtml()? headers->ComputeCaching(); } @@ -450,7 +450,7 @@ ngx_command_t ps_commands[] = { NULL }, { ngx_string("pagespeed"), - NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1| + NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1| NGX_CONF_TAKE2|NGX_CONF_TAKE3|NGX_CONF_TAKE4|NGX_CONF_TAKE5, ps_loc_configure, NGX_HTTP_SRV_CONF_OFFSET, @@ -864,19 +864,28 @@ char* ps_merge_srv_conf(ngx_conf_t* cf, void* parent, void* child) { } char* ps_merge_loc_conf(ngx_conf_t* cf, void* parent, void* child) { - ps_loc_conf_t* parent_cfg_l = static_cast(parent); - - // The variant of the pagespeed directive that is acceptable in location - // blocks is only acceptable in location blocks, so we should never be merging - // in options from a server or main block. - CHECK(parent_cfg_l->options == NULL); - ps_loc_conf_t* cfg_l = static_cast(child); if (cfg_l->options == NULL) { // No directory specific options. return NGX_CONF_OK; } + // While you can't put a "location" block inside a "location" block you can + // put an "if" block inside a "location" block, which is implemented by making + // a pretend "location" block. In this case we may have pagespeed options + // from the parent "location" block as well as from the current locationish + // "if" block. + ps_loc_conf_t* parent_cfg_l = static_cast(parent); + if (parent_cfg_l->options != NULL) { + // Rebase our options off of the ones defined in the parent location block. + ps_merge_options(parent_cfg_l->options, &cfg_l->options); + return NGX_CONF_OK; + } + + // Pagespeed options are defined in this location block, and it either has no + // parent (typical case) or is an if block whose parent location block defines + // no pagespeed options. Base our options off of those in the server block. + ps_srv_conf_t* cfg_s = static_cast( ngx_http_conf_get_module_srv_conf(cf, ngx_pagespeed)); diff --git a/test/nginx_system_test.sh b/test/nginx_system_test.sh index 7eb93ce1c..922d0297f 100755 --- a/test/nginx_system_test.sh +++ b/test/nginx_system_test.sh @@ -271,6 +271,28 @@ function run_post_cache_flush() { # nginx-specific system tests +start_test Test pagespeed directive inside if block inside location block. + +URL="http://if-in-location.example.com/" +URL+="mod_pagespeed_example/inline_javascript.html" + +# When we specify the X-Custom-Header-Inline-Js that triggers an if block in the +# config which turns on inline_javascript. +WGET_ARGS="--header=X-Custom-Header-Inline-Js:Yes" +http_proxy=$SECONDARY_HOSTNAME \ + fetch_until $URL 'grep -c document.write' 1 +OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP $WGET_ARGS $URL) +check_from "$OUT" fgrep "X-Inline-Javascript: Yes" +check_not_from "$OUT" fgrep "inline_javascript.js" + +# Without that custom header we don't trigger the if block, and shouldn't get +# any inline javascript. +WGET_ARGS="" +OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP $WGET_ARGS $URL) +check_from "$OUT" fgrep "X-Inline-Javascript: No" +check_from "$OUT" fgrep "inline_javascript.js" +check_not_from "$OUT" fgrep "document.write" + # Tests related to rewritten response (downstream) caching. if [ "$NATIVE_FETCHER" = "on" ]; then diff --git a/test/pagespeed_test.conf.template b/test/pagespeed_test.conf.template index 5150b3181..16e3bfcd9 100644 --- a/test/pagespeed_test.conf.template +++ b/test/pagespeed_test.conf.template @@ -127,6 +127,45 @@ http { } } + server { + listen @@SECONDARY_PORT@@; + server_name if-in-server.example.com; + pagespeed FileCachePath "@@SECONDARY_CACHE@@"; + + pagespeed RewriteLevel PassThrough; + set $inline_javascript "No"; + + if ($http_x_custom_header_inline_js) { + # TODO(jefftk): Turn on NGX_HTTP_SIF_CONF and figure out how to get + # pagespeed directives inside of a server location block to be respected, + # then uncomment the following line and duplicate the if-in-location test + # for if-in-server. + #pagespeed EnableFilters inline_javascript; + set $inline_javascript "Yes"; + } + + add_header "X-Inline-Javascript" $inline_javascript; + } + + server { + listen @@SECONDARY_PORT@@; + server_name if-in-location.example.com; + pagespeed FileCachePath "@@SECONDARY_CACHE@@"; + + + location / { + set $inline_javascript "No"; + pagespeed RewriteLevel PassThrough; + + if ($http_x_custom_header_inline_js) { + pagespeed EnableFilters inline_javascript; + set $inline_javascript "Yes"; + } + + add_header "X-Inline-Javascript" $inline_javascript; + } + } + server { listen @@SECONDARY_PORT@@; server_name mpd.example.com; From 7d72a7c89ab7d5a97988607fc2ba96cf4a5300aa Mon Sep 17 00:00:00 2001 From: Otto van der Schaaf Date: Tue, 8 Apr 2014 11:16:47 +0200 Subject: [PATCH 13/13] nginx-gridfs: Add configure option to build with wno-error Some modules add things to CFLAGS that will make ngx_pagespeed emit warnings at compile time. For example, nginx-gridfs will add `--std=c99` - which is no good for ngx_pagespeed. @peterbowey mentioned that -wno-error fixes the build -- so to work around, make configure add `-wno-error` when used like this: `WNO_ERROR=YES ./configure` On my system, that results in a succesfull build when nginx-gridfs is added to the module mix. Fixes https://github.com/pagespeed/ngx_pagespeed/issues/626 --- config | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config b/config index d85700f64..4c3c22508 100644 --- a/config +++ b/config @@ -111,6 +111,10 @@ case "$NGX_GCC_VER" in ;; esac +if [ "$WNO_ERROR" = "YES" ]; then + CFLAGS="$CFLAGS -Wno-error" +fi + pagespeed_include="\ $mod_pagespeed_dir \ $mod_pagespeed_dir/third_party/chromium/src \