Compare commits

...

697 Commits

Author SHA1 Message Date
Christian Grobmeier 13bee9da76 Create RETIRED.txt 2023-04-21 16:50:27 +02:00
Danila Vershinin 71e24c1c47 Refactored #1750 to support older NGINX versions (fixes #1749) 2022-06-30 17:22:12 +02:00
Otto van der Schaaf 143c4b7071 [DRAFT] Fixes for NGINX nginx 1.23.0
As of nginx 1.23 the cache control headers are re-implemented as al linked list.
This reworks our code that manipulates this header to work with that.

Still a draft: this change probably needs to be conditioned against nginx version
with ifdefs, so older version can still be built as well. Hence, still a draft.

Attempts to fix https://github.com/apache/incubator-pagespeed-ngx/issues/1749
2022-06-30 17:22:12 +02:00
Werner Beroux 9e70f6dacb Avoids relying on Bash (#1700)
This script runs fine with just Dash (SH) instead of Bash. Alpine Linux and others don't have Bash.
2020-07-30 00:37:59 +02:00
Ivan Ridao Freitas d647f4be4f Update README.md (#1677)
Fixes #1676 by using the image uploaded to GitHub.
2020-01-25 09:29:48 -05:00
Otto van der Schaaf c69649ab0a Fix error handling in ps_create_XXX_conf (#1625)
Return NULL instead of NGX_CONF_ERROR when config creation fails.

Fixes https://github.com/apache/incubator-pagespeed-ngx/issues/1623
2019-02-10 23:42:44 +01:00
Dibyendu Das f73a591738 removing the word boundary \b (#1607)
because of the word boundary \b sed fails to replace $BIT_SIZE_NAME from the binary url in macOS
2018-11-28 09:59:24 +01:00
Nico Berlee ced02f1821 Update Nginx in Docker (#1605)
Stable from 1.14.0 to 1.14.1
Mainline from 1.15.5 to 1.15.6
2018-11-15 10:32:22 +01:00
Otto van der Schaaf 24fe429a6f Dependency: update mod_pagespeed to the latest version (#1602) 2018-10-29 08:46:08 +01:00
Elena Tverdokhlib 61a4b592d2 Nginx Mainline update to 1.15.5 (#1599) 2018-10-08 18:13:55 +02:00
Nico Berlee c24e387462 Dockerfiles for Alpine 3.8/edge build with Nginx 1.14/1.15 (stable/mainline), (directory structure organised for DockerHub build compatibility). (#1598)
Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busy box. Alpine is therefor the most logical OS base for Docker Images.

Although it does not fix #1181 completely, it helps to overcome the problems of building the PSOL on Alpine,
2018-10-08 09:28:19 +02:00
Jimmy Casey 1ca55ba5d7 Fixed Spelling. (#1582) 2018-09-03 00:13:56 +02:00
David Sanders 3bb65a9055 Properly iterate modules (#1559) 2018-05-14 23:49:53 +02:00
David Sanders 449045f982 Fix setting 'gzip_proxied' when applying gzip settings (#1558) 2018-05-13 15:06:44 +02:00
David Sanders 98d353ebf4 Add wget as dependency for Debian-based distros in build script (#1553) 2018-04-28 09:05:41 +02:00
David Sanders 343851a930 Honor assume yes when installing dependencies (#1552) 2018-04-27 23:16:19 +02:00
Otto van der Schaaf 2e202e5c8d Licensing: Changes for ASF license compliance (#1528)
* Update/add license banners
* Strip "Author: " comments
* Initialize NOTICE
2018-01-19 11:21:10 +01:00
Otto van der Schaaf c48ca9e990 Update mod_pagespeed dep to current head 2018-01-12 22:06:46 +01:00
Otto van der Schaaf daf1d9446c Update repository links
Update sources to reflect that the source of truth for most of the
repositories in pagespeed/ have moved to
github.com/apache/incubator-pagespeed-*
2018-01-12 22:06:46 +01:00
Otto van der Schaaf 4f1565bb2a Update README.md (#1525)
Fix travis links
2018-01-11 21:44:27 +01:00
Otto van der Schaaf e733a838c3 Unbreak install after repo transfers (#1523)
The directory name in the zip we download from github's release
archive will be different now that the project was renamed.
It may be renamed again in the future, so try to obtain the directory
name from the zip.

Fixes https://github.com/apache/incubator-pagespeed-ngx/issues/1521
2018-01-08 17:57:39 +01:00
Otto van der Schaaf ccaa714a85 F_SETPIPE_SZ: check for existence before using (#1505)
Kernels before 2.6.35 do not have F_SETPIPE_SZ defined.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1503
2017-11-27 23:21:03 +01:00
Otto van der Schaaf ab07fb8968 Fix ngx_pagespeed installing dependency packages (#1498)
- Fix auto-install of required packages by fixing quoting (thanks @jeffkaufman!). 
- Add libuuid-devel for redhat-based distro's too.

Fixes https://github.com/pagespeed/mod_pagespeed/issues/1680
2017-11-09 00:58:49 +01:00
Otto van der Schaaf 605e61f0a7 build_ngx_pagespeed.sh: add uuid-dev (#1497) 2017-11-08 23:02:53 +01:00
Otto van der Schaaf 8de5d7e443 Update mod_pagespeed to 569affb1a2baef30a34f9df6c2f152897c0fd896 (#1495) 2017-11-01 22:29:10 +01:00
Yukihiko SAWANOBORI 49006858d1 Set buildtype from env PSOL_BUILDTYPE. (#1486) 2017-10-06 11:13:18 +02:00
Otto van der Schaaf 11f67d9bc7 Fix nginx worker 100% cpu usage (spinning on write returning EAGAIN)
Bump the pipe capacity, because running out of buffer space may cause
a write to spin indefinitely on EAGAIN.
Bumping the pipe capacity should eliminate the problem in practice,
though in theory the module could still be subject to it.
For now, leaving behind a todo with a suggested solution (should
the problem ever show up again).

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1380
2017-09-29 09:06:33 +02:00
Otto van der Schaaf 6f94abef67 nginx-1.13.4: use preprocessor define instead of const for comparison (#1483)
Address a mistake I made in https://github.com/pagespeed/ngx_pagespeed/pull/1458

While testing the draft for 1.12.34.3 I noticed that older nginx
versions would fail to compile. Switch kNginx13_1_4 to a #define so we
can use it to properly compare.
2017-09-25 22:56:58 +02:00
PikachuEXE 662c1e1c5a Fix compiling issue with older nginx (#1470) 2017-09-18 07:27:59 +02:00
PikachuEXE a897f64ce8 ! Fix syntax of script (#1469) 2017-09-18 07:27:03 +02:00
Otto van der Schaaf 4d9e5fcb0c Fix ignored return code in ps_simple_handler() (#1468)
Fix for https://github.com/pagespeed/ngx_pagespeed/issues/1465
2017-09-11 21:11:50 +02:00
PikachuEXE 65761a2393 Update build script to pass --skip_deps when called with --no-deps-check (#1461) 2017-08-31 17:53:41 +02:00
Otto van der Schaaf 76500396ff Update mod_pagespeed testing dependency (#1460)
* Update mod_pagespeed testing dependency
(mod_pagespeed commit a7c39a1b5a14f1422fef19e8e9dcb11074ba1c65)
* Add explicit default server{} on secondary_port to so that the recent
tests for css parser improvements land on a vhost with the right filters
enabled.
2017-08-22 16:27:41 +02:00
Otto van der Schaaf ef3899515e Adress @jmarantz his comment from #1453's review (#1458)
PR #1453 was merged too soon, using this PR to address
https://github.com/pagespeed/ngx_pagespeed/pull/1453#discussion_r134222719

(Sorry Josh!)
2017-08-21 21:00:49 +02:00
Otto van der Schaaf c67f664244 nginx 1.13.4: Fix compilation error (#1453)
* Compilation of ngx_pagespeed broke with the following commit in
nginx: https://github.com/nginx/nginx/commit/129b06dc5dfab7b4513a4f274b3778cd9b8a6a22
This change intends to unbreak it while maintaining backwards
compatibility.

* updates the nginx testing-dependency to 1.13.4

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1451
2017-08-21 12:25:50 +02:00
Otto van der Schaaf 54847f6d1d point mod_pagespeed submodule to the latest rev (#1433)
* point mod_pagespeed submodule to the latest rev
* Add missing vhost for test "Image rewrite with flush"
2017-06-27 23:53:31 +02:00
Otto van der Schaaf 5631800479 Don't respond with an entitybody to HEAD requests for html (#1376)
Mind r->header_only when processing the response body.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1375
2017-02-07 12:02:43 +01:00
Jeff Kaufman a7d1f91dc3 standby: add standby mode (#1365)
* standby: add standby mode

Add standby mode for ngx_pagespeed, equivalent to "off" in mod_pagespeed.

With this change "off" is deprecated, and people should use "unplugged" instead.

* Update mps to include test file

* update mps

* update mps

* update mps
2017-01-25 13:24:15 -05:00
Jeff Kaufman 61b949c5e5 devel: simplify ngx_pagespeed development flow (#1363)
* provide scripts/rebuild.sh so you don't have to run make commands in
  two directories
* make test/run_tests.sh able to run with no arguments by setting good defaults.
2017-01-20 09:29:34 -05:00
Jeff Kaufman 5b307745ce fix TEST_TO_RUN in ngx_pagespeed (#1364)
Eventually we'll convert remote_config_system_test.sh and nginx_system_test.sh
to use run_test, but until then when TEST_TO_RUN is specified we should skip
the tests in those files and just run system/system_test.sh
2017-01-20 09:28:54 -05:00
Jeff Kaufman f78058b6c4 Allow use of "unplugged" without crashing (#1362)
* update mps

* stop crashing when unplugged

* formatting fixes
2017-01-19 13:48:01 -05:00
Jeff Kaufman 8a0b080229 install: add --additional-nginx-configure-arguments option (#1344)
Instead of requiring people to answer a prompt to specify which additional
arguments they would like nginx to be built with, allow people to specify
arguments like this on the command line.  The quoting is not ideal, since
it's important to pass spaces etc properly all the way through to the
underlying commands, but I give an example in the help text.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1340
2017-01-03 07:07:50 -05:00
Jeff Kaufman cb56136fe1 travis: send emails to new pagespeed-ci group instead of individual devs (#1341) 2016-12-19 13:45:56 -05:00
Jeff Kaufman a4ac43e4d4 travis: get it building and passing tests (#1339)
* travis: get it building and passing tests

I initially planned to get this working on Ubuntu 12, but decided it wasn't
worth it and switched to Ubuntu 14 (Trusty).  Now it passes tests on Travis, so
I've added other people's emails back to the set of people to send emails to.

Also update mps while we're at it.

* update mps

* update mps

* ngx_pagespeed depends on luuid

* update mps
2016-12-19 13:21:33 -05:00
Jeff Kaufman 80c4b7e97b config: use Release binaries when building with --with-debug if that's all that's available (#1332)
* config: use Release binaries when building with --with-debug if that's all that's available

* prompt the user before going ahead and using release binaries

* exit 1, reword message
2016-12-14 10:13:45 -05:00
Jeff Kaufman 0c7d64221c licensing: correct bash license comments (#1336)
A few bash files were missing license comments
2016-12-12 13:40:41 -05:00
Jeff Kaufman 68185b8605 installer: allow --dynamic-module to be used with tags (#1334)
* installer: allow --dynamic-module to be used with tags

A user-friendly check with dynamic module building tries to warn people early if the version of ngx_pagespeed they're building is too old to be compiled as a dynamic module, but this can't work with tags.  If we're given something other than a numeric version number, don't try to perform this check.

Fixes https://github.com/pagespeed/mod_pagespeed/issues/1443
2016-12-08 15:14:12 -05:00
hillsp 7f225e2e70 Add format_binary_url.sh (#1331) 2016-12-06 13:16:29 -05:00
Jeff Kaufman 4d728fc081 branch-names: now that trunk-tracking is master, update references (#1330) 2016-12-06 12:01:50 -05:00
hillsp a399e04a00 Delete prepare_psol.sh (#1310)
Replaced with install/build_psol.sh  in mod_pagespeed.
2016-12-06 11:43:13 -05:00
Jeff Kaufman 247a821564 install: add support for building psol from source and setting up for development (#1313)
* adds support for `--psol-from-source` so you don't need binary modules, and `--devel` so you can run our tests without going and getting all our dependencies
* adds submodules for testing: mod_pagespeed, ngx_cache_purge etc
* adds support for running as:
```
git clone git@github.com:pagespeed/ngx_pagespeed.git
cd ngx_pagespeed/
git checkout <branch>
scripts/build_ngx_pagespeed.sh [options]
```
* depends on the scripts @hillsp is working on so that we can just check out mod_pagespeed and ask it to build and rebuild itself
* adds colors to output to make it easier to read
2016-12-06 09:21:42 -05:00
hillsp f7502b1b40 Mark CentralControllerPort as Experimental (#1326) 2016-11-30 14:43:55 -05:00
Joshua Marantz 617f0e6bee Add a new server-name to help test a repro for broken pagespeed resources (#1324)
after ipro-recorded optimations.

for https://github.com/pagespeed/mod_pagespeed/issues/1145
and https://github.com/pagespeed/ngx_pagespeed/issues/1319 .
2016-11-21 14:11:56 -05:00
hillsp 42115f54da Need clone --recursive 2016-11-21 10:49:59 -05:00
hillsp 3d9f2aee37 First pass at modernising travis.yml 2016-11-21 10:38:05 -05:00
Joshua Marantz d77c7eac17 test config for disabling rewriters in ajax (#1320) 2016-11-14 08:09:44 -05:00
Jeff Kaufman 97134d951e test: run_tests.sh should just assume 8050 and 8051 (#1315)
Right now run_tests.sh assumes it has 8053 and 9991 without causing any
problems.  Start assuming we have 8050 and 8051 as well instead of
requiring people to pass them in.
2016-11-03 14:58:05 -04:00
Jeff Kaufman 17e4162334 remote-config: renaming paths to be more informative (#1312) 2016-11-03 07:03:31 -04:00
Jeff Kaufman d70dcbc4d0 remote-config: use one port for testing, against a new python server (#1293)
* remote-config: use one port for testing, against a new python-based server

* properly reference remote configu urls
2016-11-01 12:29:25 -05:00
Sen Jiang 62c66e2c9c Fix non-zero exit code even if the script succeed (#1302)
The script succeeded but the exit code is 1 because it's not a dryrun so the last command failed.
2016-10-25 09:35:01 -05:00
Jeff Kaufman 09478cac70 installer: reference the --no-deps-check option properly (#1305) 2016-10-24 12:00:27 -05:00
hillsp 14b4723326 Fix sparsehash path (#1300) 2016-10-20 13:55:21 -04:00
Maks Orlovich ad41e72a83 Our config tests need to be compiled with --std=c++11 now (#1295) 2016-10-13 14:50:41 -04:00
Jeff Kaufman 7a54f88ae8 config: give full path to autoconf.err if 'checking for psol' fails. (#1294) 2016-10-13 10:42:24 -04:00
Jeff Kaufman e7be591e91 testing: check_flushing needs to know the host name (#1292) 2016-10-12 18:02:56 -04:00
Jeff Kaufman 711b6a4954 install: fix quoting (#1291)
We want to parse $additional_configure_args into an array the way the
shell would, which we're using eval for.  But because we were missing
quotes whitespace was being stripped.  Basically:

    $ function lines() { for x in "$@"; do echo "$x"; done; }

    $ lines a "b   c" d
    a
    b   c
    d

    $ a='a "b   c" d'
    $ eval e=($a)
    $ eval f=("$a")

    $ lines "${e[@]}"
    a
    b c
    d

    $ lines "${f[@]}"
    a
    b   c
    d

We were doing this like e when we should have been doing it like f.
2016-10-12 12:22:37 -04:00
hillsp 916ff52307 Fix travis.yaml for new DEPS file 2016-10-07 21:44:32 -04:00
Jeff Kaufman cd004c6d0c tests: check flushing changed its arguments (#1288) 2016-10-07 15:51:24 -04:00
Jeff Kaufman 0fd456fa57 build_ngx_pagespeed: handle quoted arguments (#1286)
* build_ngx_pagespeed: handle quoted arguments

If you enter --with-cc-opt='-arg1 -arg2' when the script asks for
additional arguments we want that to remain as one chunk all the way
through to being a single argument to ./configure
2016-10-05 08:26:04 -04:00
Jeff Kaufman 3b226aab7e install: default to latest-beta (#1283)
* install: default to latest-beta

* latest stable instead
2016-10-03 15:16:24 -04:00
hillsp 90627b1fbd Add controller tests for nginx (#1280) 2016-09-26 13:55:22 -04:00
Jeff Kaufman 6cb4b8dde3 We need -lstdc++ to come after psol.a (#1273) (#1274) 2016-09-24 16:04:52 -04:00
Jeff Kaufman d2af4962e6 load-from-file: config for testing load from file with a low size limit (#1268)
nginx side of the fix for https://github.com/pagespeed/mod_pagespeed/issues/1386
2016-09-23 18:20:26 -04:00
Jeff Kaufman b997d79ea7 install: add script to install nginx_pagespeed (#1263)
install: add script to install nginx_pagespeed

Automated version of the instructions on https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source

Tested on fresh vms of debian8, centos 6 and 7, rhel 6 and 7, and ubuntu lts 12, 14, and 16

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1262
2016-09-21 07:48:03 -04:00
Joshua Marantz 0baa230bd7 Add default setting for whether to test with a controller port. (#1278)
* Add default setting for whether to test with a controller port.

* Use RUN_CONTROLLER_TEST, which will actually be defaulted in
system/system_test.sh.  Comment out the controller port configuration
in the default nginx template.

* Finish up the conditionalization of the babysitter tests.

* Run the reload tests even with the controller off.

* clean up the diffs a little.
2016-09-20 15:42:47 -04:00
Joshua Marantz 1118910228 the remote config test is in a separate script now, so run it from the master test script (#1260) 2016-09-19 19:25:24 -04:00
hillsp 7584be2668 Work-around broken GCE Ubuntu repo 2016-09-15 16:23:11 -04:00
hillsp c8f8aff23f Add GLOBAL_STATISTICS_URL variable (#1270) 2016-09-12 13:52:06 -04:00
Otto van der Schaaf 76eeec5972 special-responses: fix for hanging sometimes on special responses (#1238)
After calling ngx_http_filter_finalize_request return NGX_DONE
as we are still in pre-access phase. This bug shows up when the
"special" response is generated from, for example, php as opposed
to a static file.

Second part of the fix for
https://github.com/pagespeed/ngx_pagespeed/issues/1146
2016-09-07 10:49:53 +02:00
hillsp 2d24ec68f1 Additional suppressions for new RE2 (#1266) 2016-09-06 10:07:40 -04:00
Maks Orlovich 269ed10ed5 Also look for headers in /url in mod_pagespeed tree (#1264)
This is needed because the current GURL implementation there --- and hence
google_url.h needs an extra compat header that's there.
2016-09-02 15:11:50 -04:00
Jeff Kaufman 94dde75a86 combine-ids: add configuration for system test (#1259) 2016-09-01 15:04:03 -04:00
Joshua Marantz 9b47332d9c allow sloppy exit (#1258)
* set up a test subdir with cc:public

* allow 'adding function to sequence' warnings on shutdown, without breaking the nginx debug tests
2016-08-29 17:06:26 -04:00
Egor Suvorov 4b7a7cc15e Make NgxMessageHandler::FileMessage() add data into internal buffer as well (#1255) 2016-08-25 15:10:46 -04:00
Jeff Kaufman f8f32efb97 Test shm checkpointing. Relies on shm checkpointing implementation in mod_pagespeed. (#930) 2016-08-23 07:46:20 -04:00
Otto van der Schaaf 3015cf0372 Allow processing of script variablies in more options (#1239)
All directory- and process- scoped options are allowed with this
change, when "ProcessScriptVariables all" is specified.

Option list compiled from:
https://docs.google.com/spreadsheets/d/1qJSUZqd2Te-4SDtm1Av6u-AckNv_oHEp1qdaUjNqZoM/edit#gid=0
2016-08-10 21:04:47 +02:00
Jeffrey Crowell 8644e5d83d Update .travis.yml 2016-08-09 17:45:19 -04:00
Jeff Kaufman 7fd0f3ee2f rewrite-options: don't turn on CoreFilters just because of query params (#1228)
Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1190
2016-08-04 10:44:46 -07:00
Jeffrey Crowell a919a926f4 nginx side of https://github.com/pagespeed/mod_pagespeed/issues/1371 (#1235)
nginx side of the change
https://github.com/pagespeed/mod_pagespeed/issues/1371
2016-08-03 13:09:22 -05:00
Jeff Kaufman ed5a43ef72 rewrite-domains: add test configuration for rewriting static assets (#1223)
Needed for fixing https://github.com/pagespeed/mod_pagespeed/issues/1350
2016-08-02 11:46:20 -07:00
Jeff Kaufman ee27b5bd7a json: add content-type and cache-control for example json file (#1224) 2016-07-18 11:15:31 -04:00
Otto van der Schaaf 572f59299e Check options->IsAllowed() before rewriting html. (#1225)
Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1226
2016-07-15 20:41:19 +02:00
Otto van der Schaaf ebe7c61f4f Make ngx_pagespeed behave like mod_pagespeed with regard to Flushing (#1217)
This change makes ngx_pagespeed listen to the FollowFlushes option.
When set to on (=default), ngx_pagespeed will forward incoming flushes
to ProxyFetch. When writing output, we'll now also set the flush flag on
the buffers we are about to send downstream.

Companion to mps commit: https://github.com/pagespeed/mod_pagespeed/commit/02de03e825bbd1f8d4ad4e1a1bef5263a16f3857
2016-07-12 12:26:38 -04:00
Otto van der Schaaf e542347a20 Fix for when there is only server-level configuration (#1218)
When there is no top-level configuration but only server configuration,
we don't have main options to set and consider. This prevents
a NULL dereference in that case. (Later on we'll writes out a message
about why we cannot startup with this configuration).
2016-07-06 16:13:05 +02:00
Otto van der Schaaf b1d9fbf544 Fix segfault when there's no http{} block in nginx.conf (#1221)
Should fix https://github.com/pagespeed/ngx_pagespeed/issues/1220
2016-07-06 16:12:04 +02:00
Jeff Kaufman 44626a4121 url-valued-attributes: tests for mod_pagespeed/f2f0075 2016-06-24 16:54:23 -04:00
Joshua Marantz 271b0c1f15 set up a test subdir with cc:public (#1215) 2016-06-16 09:54:06 -04:00
hillsp 1bb10ec599 Suppress controller warnings in test, fix up kill signals (#1210)
* Suppress controller warnings in test, fix up kill signals

* Switch valgrind shutdown to QUIT
2016-06-10 14:54:49 -04:00
Jeffrey Crowell c4fc99c5ae README.md: fix link in travis badge 2016-06-08 13:06:25 -04:00
Jeffrey Crowell 4c09bac0c4 svn of depot_tools is going away, migrate to git. (#1211)
for some reason we were still using the svn for travis here, but git for everything else...
2016-06-08 13:05:22 -04:00
Maks Orlovich 03d69e53b1 Update for API change: kProcessScope is about to become kLegacyProcessScope (#1205)
The renaming is to make it clear that kProcessScopeStrict (aka what
ngx_pagespeed does for everything already) is what new code should be
using, rather than current kProcessScope/upcoming kLegacyProcessScope
which does weird backwards compatible things in mod_pagespeed.
2016-05-30 12:52:41 -04:00
Maks Orlovich 15c6f7c345 Make sure RewriteDriverFactory::default_options gets the top-level proces-scope options. (#1203)
Needed for ImageMaxRewritesAtOnce to work with latest revisions.
2016-05-20 10:07:24 -04:00
Joshua Marantz d7f48d88c6 Pass the install-path into Makefile (#1200)
* Pass the install-path into Makefile, rather than having the Makefile
depend on PWD.

* Move the double-quotes be before the value, to be consistent with other
Makefiles.
2016-05-16 13:32:28 -04:00
Steve Hill fd26b873e9 Remove stray -q on pgrep. 2016-05-13 17:47:09 -04:00
hillsp d6c395151f Fix nginx_system_test so that it doesn't wait for verify_nginx_release.sh (#1199)
or wait indefinitely if it can't kill nginx.
2016-05-13 16:06:38 -04:00
Joshua Marantz dab6b8ac04 During system-tests, don't write into the source-controlled htdocs area. (#1197)
Instead, use a new (not-yet-committed) target in Makefile.tests to build
a mirror htdocs in test/tmp/root that sym-links the large readonly
section and deep copies the test areas for purge and flush tests.
2016-05-13 08:44:14 -04:00
hillsp 77cd95b552 Fix IPRO and missing Content-Length headers in 32-bit builds. (#1196) 2016-05-11 13:34:00 -04:00
Joshua Marantz be7837507f respect purge requests when serving ipro requests from ngx_pagespeed (#1193)
* respect purge requests when serving ipro requests from ngx_pagespeed

* Add TODO to share common base with ApacheFetch.
2016-05-11 11:08:04 -04:00
Jeffrey Crowell 7094df4c11 add build status indicator for trunk-tracking (#1195) 2016-05-11 07:56:34 -07:00
Nikolay Kolev 76bc257af6 Removed the redundant bracket. (#1189) 2016-05-05 14:44:59 -04:00
Jeffrey Crowell 3208d56aa4 add travis to trunk-tracking branch (#1186)
* add travis to trunk-tracking branch
2016-05-02 16:14:16 -04:00
hillsp 090ec03a68 System test updates for CentralControllerPort. (#1182) 2016-04-28 15:45:29 -04:00
Maks Orlovich e885e02a3c Fix build with recent nginx which lacks NGX_CONF_MULTI (#1185) 2016-04-26 15:37:26 -04:00
Jeffrey Crowell 6f5042020b fix up the description in the run_tests.sh (#1176)
run_tests had the wrong invocation of the script in the comments. fix
that.
2016-04-11 16:52:02 -04:00
Jeff Kaufman f3063e2daa Companion to mps change to set s-maxage on unoptimized ipro resources (#1171) 2016-04-07 16:02:02 -04:00
Otto van der Schaaf 56ee9ff24e Fix for async waits vs client aborts and HTTP/2 RST_FRAMES
This change makes nginx close the request when we receive a close

event or RST_STREAM while waiting for an async PSOL op to complete

by setting a read event handler, as inspired by the limit request

module from nginx.



Should fix https://github.com/pagespeed/ngx_pagespeed/issues/1146
2016-04-07 10:35:19 -04:00
hillsp b290a4c8a3 Merge pull request #1170 from pagespeed/cheesy_115698600
Add grpc headers to search path.
2016-04-04 17:54:12 -04:00
Jeff Kaufman 297b4ab34b handle additional warnings 2016-03-29 10:07:09 -04:00
Joshua Marantz b975ae59df Merge pull request #1164 from pagespeed/jmarantz-remove-cache-html
remove a no-longer-needed arg to ProxyFetchFactory::InitiatePropertyC…
2016-03-28 13:51:33 -04:00
Joshua Marantz c0e917801d remove a no-longer-needed arg to ProxyFetchFactory::InitiatePropertyCacheLookup 2016-03-28 13:42:28 -04:00
Maks Orlovich a3bc2cae03 Merge pull request #1157 from pagespeed/morlovich-cpp11-on
Turn on C++11 for all compilers, not just clang.
2016-03-17 10:02:40 -04:00
Maks Orlovich 7fe4e09076 Turn on C++11 for all compilers, not just clang.
Explain why we do it via config.make better.
Remove partial workaround for config.make not invoked for dynamic modules,
nginx dev fixes the root issue, and the workaround is insufficient anyway.
2016-03-16 15:42:42 -04:00
Jeff Kaufman ee20289863 Merge pull request #1156 from pagespeed/jefftk-psauxww
controller: don't fail tests when running in emacs
2016-03-15 17:05:10 -04:00
Jeff Kaufman c3f2858e31 controller: don't fail tests when running in emacs
Apparently, when running in emacs and piped into another command, ps limits
it's output to COLUMNS making check_process_names fail.  Telling ps to use
wide, wide output with 'ww' fixes this.

Additionally, use check_from so that if this test does fail we can debug
it better, seeing what grep was looking at.
2016-03-15 16:36:52 -04:00
Otto van der Schaaf 59005bec88 Merge pull request #1150 from pagespeed/oschaaf-trunk-tracking-issue-1148
NgxFetch: Log url and error when url parsing fails.
2016-03-11 14:53:00 +01:00
Otto van der Schaaf 6634754dba NgxFetch: Log url and error when url parsing fails.
Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1148
2016-03-11 14:34:24 +01:00
Jeff Kaufman a9142f0003 Merge pull request #1105 from pagespeed/oschaaf-trunk-tracking-issue-1064
vary-header: Emit a single vary header in the IPRO flow
2016-03-08 06:21:46 -08:00
Jeff Kaufman 8efb831ba4 Support centralized process changes in github.com/pagespeed/mod_pagespeed/commit/9bf7523 2016-03-07 16:14:43 -05:00
huibaolin fcbe51efaf Merge pull request #1145 from pagespeed/huibao-webp
Add system tests for image format, quality, and response in IPRO
2016-03-07 11:41:53 -05:00
Kees Spoelstra 08e284f9cb Strip subresource hints pagespeed automatic system test configuration
Corresponding changes for:
- pull https://github.com/pagespeed/mod_pagespeed/pull/1204
- issue Strip subresource hints #973 https://github.com/pagespeed/mod_pagespeed/issues/973
2016-03-07 10:50:59 -05:00
Huibao Lin 8582bab69c Add system tests for image format, quality, and response in IPRO 2016-03-07 09:58:44 -05:00
Jeff Kaufman 5264647a65 Merge pull request #1139 from pagespeed/oschaaf-trunk-tracking-issue-1138
IPRO: Copy the cache control value to ensure a correct lifetime
2016-03-03 11:15:10 -05:00
Otto van der Schaaf 85d0db2550 IPRO: Copy the cache control value to ensure a correct lifetime
Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1138
2016-03-02 23:42:36 +01:00
hillsp 8e25b58597 Merge pull request #1130 from pagespeed/cheesy_115114559
Update protobuf path for non chromium version
2016-02-23 15:07:37 -05:00
Steve Hill 6eee387802 Update protobuf path for non chromium version 2016-02-22 17:52:55 -05:00
huibaolin 2315173946 Merge pull request #1125 from pagespeed/huibao-webp
Allow varying on Accept header for ipro-for-browser.example.com
2016-02-19 15:54:52 -05:00
Huibao Lin 54bd8bf4f8 For backward compatibility, only allow varying on Accept header for ipro-for-browser.example.com 2016-02-18 11:29:27 -05:00
Jeffrey Crowell 60f91becb7 Merge pull request #1122 from pagespeed/oschaaf-trunk-tracking-issue-1120
Fix shutdown when ngx_pagespeed is completely disabled.
2016-02-17 10:29:39 -05:00
Jeffrey Crowell d959f01848 Merge pull request #1115 from pagespeed/oschaaf-trunk-tracking-dynamic-modules
Support building ngx_pagespeed as a dynamic module
2016-02-16 11:00:53 -05:00
Otto van der Schaaf f60c754d82 Fix shutdown when ngx_pagespeed is completely disabled.
Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1120
2016-02-15 10:54:53 +01:00
Otto van der Schaaf 09f53881de Support building ngx_pagespeed as a dynamic module.
As of 1.9.11, nginx supports loading dynamic modules
This change makes us support building ngx_pagespeed.so

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1116
2016-02-13 00:10:39 +01:00
Prayag Verma 929c5c5908 Fix a typo
`neet` → `need`
2016-02-11 13:18:13 -05:00
Piotr Sikora 064ced104d Fix build with nginx-1.9.11+.
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2016-02-10 15:03:45 -05:00
Maks Orlovich a73dc7ba74 Merge pull request #1103 from pagespeed/morlovich-ua-tweak-for-fontservice
Adjust our UA string to fix to make it compatible with fonts.g.c parsing on IE11.
2016-02-08 16:18:21 -05:00
Otto van der Schaaf b081bb7aec vary-header: Emit a single vary header in the IPRO flow
The report from some time ago mentioned three Vary: headers,
but I can now only reproduce two using trunk-tracking plus the
original repro-configuration.

This fix unflags r->gzip_vary as set by the gzip module when PSOL
hands us Vary: Accept-Encoding, to make sure that nginx's core
header filter doesn't append another one.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1064
2016-01-28 03:37:01 +01:00
Maks Orlovich 0a60e0ef8b Adjust our UA string to fix to make it compatible with fonts.google.com parsing on IE11.
Counterpart of:
https://github.com/pagespeed/mod_pagespeed/commit/f3639e84c0196a5f5151ff5e54ad57285db09b37
2016-01-27 09:16:49 -05:00
Maks Orlovich 1926c78ca2 Merge pull request #1102 from pagespeed/morlovich-no-more-spdy-specific-config
Adjust to library API change: no more spdy-specific config.
2016-01-25 15:33:35 -05:00
Maks Orlovich c3598134ee Adjust to library API change: no more spdy-specific config. 2016-01-25 12:33:29 -05:00
Jeff Kaufman 43f09a877b Merge pull request #1101 from pagespeed/oschaaf-trunk-tracking-basefetch-valgrind
Fix valgrind complaint caused by NgxBaseFetch
2016-01-25 11:05:37 -05:00
Jeff Kaufman d023bb35f6 Merge pull request #1098 from pagespeed/oschaaf-trunk-tracking-rzero-crash
Eliminate CHECK that fails (rarely) during the IPRO lookup.
2016-01-22 10:12:17 -05:00
Otto van der Schaaf 60c1f4cc4e Fix valgrind complaint caused by NgxBaseFetch
We should not use r->connection after we finalize the request.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1100
2016-01-22 16:06:42 +01:00
Otto van der Schaaf b88e067c6d Eliminate CHECK that fails (rarely) during the IPRO lookup.
Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1096
2016-01-21 22:08:43 +01:00
Jeff Kaufman b214fb43e3 Merge pull request #1061 from pagespeed/oschaaf-trunk-tracking-add-resource-header
AddResourceHeader: Add test configuration
2016-01-19 13:26:01 -05:00
Joshua Marantz 9e6048f771 Merge pull request #1092 from pagespeed/jmarantz-ipro-flow-cache-not-flaky
remove 'IPRO flow uses cache as expected' from flaky-list, ...
2016-01-05 15:11:46 -05:00
Maks Orlovich 653875cb68 Merge pull request #1076 from pagespeed/morlovich-h2-bit
Store whether h2 is in use in RequestContext.
2016-01-05 12:35:51 -05:00
Joshua Marantz a512d95258 remove 'IPRO flow uses cache as expected' from flaky-list, but strip out 'Fetch timed out' from log-warning check 2016-01-05 11:46:35 -05:00
Otto van der Schaaf a4441220b1 Merge pull request #1085 from pagespeed/oschaaf-trunk-tracking-internal-redirect-crasher
Fix crasher on 404 .pagespeed. resources w/a custom location
2016-01-04 22:03:05 +01:00
Jeffrey Crowell 374ee1c750 Merge pull request #1089 from pagespeed/crowell-reapply-744
reapply:  location-header: tweak location header handling
2015-12-31 10:54:29 -05:00
Jeffrey Crowell 059dd20b10 reapply: location-header: tweak location header handling
- Fix potentially sending the location header into PSOL twice.
- Be more thorough when unsetting the location header

Attempts to fix #725

from oschaaf
2015-12-31 10:46:39 -05:00
Otto van der Schaaf 1964ef5219 Fix crasher on 404 .pagespeed. resources w/a custom location
- Fix nginx-side flow so we handle .pagespeed. resources ok
  when they will land on a customized 404 internal location.
- Additionally, check for a wiped request context and make sure
  we do not dereference a null pointer, which is what hurt in
  the flow we entered above as the IPRO lookup still was
  generating events while the nginx side request context was
  gone.
- Also, as a preliminary measure, do not check fail when we
  receive a stale event originating from a NgxBaseFetch that
  is no longer associated with our request context.
  Do log a warning so we'll hear about this happening either
  through system test failures or a bug report.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1081
2015-12-28 15:59:13 +01:00
Jeff Kaufman 56a5d41ec3 Restore dropped fix for #957
@rfnx fixed #957 in acb89a, but this was accidentally merged to master
instead of trunk-tracking.  I checked for this sort of problem as part
of the 1.10 release, but missed this commit.  Restored.

Fixes #1054
2015-12-18 15:01:15 -05:00
Jeff Kaufman 7ee1efe0dd Merge pull request #1071 from pagespeed/oschaaf-trunk-tracking-log-debug-noise
log: initialize logging earlier
2015-12-17 11:36:34 -05:00
Maks Orlovich eb2a81ee79 Store whether h2 is in use in RequestContext. 2015-12-15 09:29:02 -05:00
Otto van der Schaaf 37e1c3618a log: initialize logging earlier
It turns out to be possible to initialize logging earlier by
grabbing the log from a global ngx_cycle structure.

This makes us start logging earlier, yet loses the
"No threading detected ..." messages both from stderr and
in error.log when nginx initially starts.

With this change, these messages will now be logged as we start
logging earlier:

"
flush
.
"

These originate from SystemCachePath::CacheKey which appends
newlines to the key, and the resulting cache key ends up being
logged. We might want to change that, because the resulting
lines in error.log look weird and might raise questions.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/895
2015-12-11 12:02:21 +01:00
Jeffrey Crowell df498ea788 Merge pull request #1067 from pagespeed/crowell-fix-gcc5
add flags for new GCC on config tests
2015-12-10 15:45:47 -05:00
Jeffrey Crowell 4b4d353156 add flags for new GCC on config tests
closes #1066
2015-12-10 15:41:44 -05:00
Maks Orlovich c9d4912746 Merge pull request #1050 from pagespeed/morlovich-compiler-req
Add compiler version checks for what we want to support going forward.

Also make us actually build with clang (the log_message_handler.cc change
and config.make change)
2015-12-09 14:50:11 -05:00
Otto van der Schaaf 2b74f6bed3 AddResourceHeader: Add test configuration
nps side of https://github.com/pagespeed/mod_pagespeed/pull/1200
2015-12-09 04:35:24 +01:00
Maks Orlovich f1a6cd0ade Whitespace tweak 2015-12-07 10:01:23 -05:00
Joshua Marantz 0c01c0644e Merge pull request #1057 from pagespeed/jmarantz-2-pass-ipro
suppress errors on new 2-pass and 3-pass ipro tests
2015-12-02 16:45:48 -05:00
Joshua Marantz 14aa4fd962 suppress errors on new 2-pass and 3-pass ipro tests 2015-12-02 15:01:37 -05:00
Joshua Marantz 36a7ff9543 Merge pull request #1056 from pagespeed/jmarantz-no-error-on-slow-ReadFile
do not consider it a test failure to get a slow ReadFile operation.
2015-12-02 08:31:34 -05:00
Joshua Marantz 706577a34b do not consider it a test failure to get a slow ReadFile operation. 2015-12-02 08:27:47 -05:00
Otto van der Schaaf 6703b2d76e Merge pull request #1055 from pagespeed/oschaaf-trunk-tracking-location-header-handling
location-header: Be careful with headers_out->location
2015-12-01 18:56:53 +01:00
Otto van der Schaaf 40c05b4a4f location-header: Be careful with headers_out->location
Only set headers_out->location when the upstream originally did
as well. If the Location: header value involved starts with "/"
nginx will absolutify it, ignoring any X-Forwarded-Proto header
in the process.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/819
(Confirmed: https://github.com/pagespeed/ngx_pagespeed/issues/1029)
Hopefully fixes https://github.com/pagespeed/ngx_pagespeed/issues/711
2015-12-01 18:55:02 +01:00
Maks Orlovich bc875647f1 Add compiler version checks for what we want to support going forward,
and make us actually build with clang (the log_message_handler.cc change
and config.make change)
2015-11-25 13:44:13 -05:00
Maks Orlovich f88a0763fd Merge pull request #1048 from pagespeed/morlovich-buildflag
Pass in -D_GLIBCXX_USE_CXX11_ABI=0, so people using gcc-5.x can use our psol.a
2015-11-25 08:56:16 -05:00
Maks Orlovich 239ca9aa80 Pass in -D_GLIBCXX_USE_CXX11_ABI=0, so people using gcc-5.x can use psol.a
we built with 4.8

See issue 942
2015-11-24 15:16:06 -05:00
Jeff Kaufman 37c51d3b9e Merge pull request #1042 from pagespeed/jefftk-content-experiment
Add ContentExperiment support
2015-11-24 11:46:04 -05:00
Jeff Kaufman 2468257e2d Add ContentExperiment support 2015-11-20 16:39:02 -05:00
Jeff Kaufman 4628e1c0ea Merge pull request #1035 from pagespeed/jefftk-script-var-testing
Support script variables in ShardDomain
2015-11-19 11:01:41 -08:00
Jeff Kaufman 7f98ab448b Merge pull request #1047 from pagespeed/jefftk-ngx-brotli
Fix interaction with ngx_brotli module.
2015-11-18 11:20:17 -08:00
Piotr Sikora 103c479fbb Fix interaction with ngx_brotli module.
Reported by George Liu (eva2000) on GitHub (issue #1021).

Signed-off-by: Piotr Sikora <piotrsikora@google.com>

Conflicts:
	config
2015-11-16 18:26:30 -05:00
Jeffrey Crowell 887bd8fa98 Merge pull request #1046 from pagespeed/crowell_content_encoding
add content_encoding to headers_out
2015-11-16 11:09:04 -05:00
Jeffrey Crowell 804f234268 add remaining shortcuts to headers_out_t
this change is required for gzip cache change going into mod_pagespeed.
2015-11-16 10:56:23 -05:00
Jeff Kaufman ea82f0de19 Support script variables in ShardDomain 2015-11-02 10:08:00 -05:00
Jeff Kaufman 5f312820e5 Merge pull request #974 from pagespeed/jefftk-handler-restrictions
Add support for blocking access to our handlers.
2015-11-02 08:18:10 -05:00
Jeff Kaufman 7efac4ac4e Merge pull request #1028 from pagespeed/oschaaf-trunk-tracking-issue-1015
IPRO+MPD: Make In-Place-Resource-Optimization with MapProxyDomain work
2015-10-28 13:30:04 -04:00
Otto van der Schaaf 634b813071 IPRO+MPD: Make In-Place-Resource-Optimization with MapProxyDomain work
Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1015

Pull with MPS Side for this change:
https://github.com/pagespeed/mod_pagespeed/pull/1161
2015-10-27 18:11:35 +01:00
Joshua Marantz d30972985b Merge pull request #1026 from pagespeed/jmarantz-remove-set-ua
Don't call RewriteDriver::SetUserAgent on the UA in the request-headers.
2015-10-22 15:17:15 -04:00
Joshua Marantz 3a6e833eae Don't call RewriteDriver::SetUserAgent on the UA in the request-headers.
RewriteDriver::SetRequestHeaders already pulls the UA from the request-headers.
2015-10-22 14:19:00 -04:00
Joshua Marantz 90c8ac8a12 Revert "Don't call RewriteDriver::SetUserAgent as the user-agent is already in the request-headers"
This reverts commit 6ccc1c513b.
2015-10-22 14:13:01 -04:00
Joshua Marantz 6ccc1c513b Don't call RewriteDriver::SetUserAgent as the user-agent is already in the request-headers 2015-10-22 13:20:00 -04:00
Jeff Kaufman fe47eeb4f3 Add support for blocking access to our handlers.
Nginx side of the fix for https://github.com/pagespeed/mod_pagespeed/issues/1088
2015-09-18 09:03:01 -04:00
Joshua Marantz e42f61e263 Merge pull request #1002 from pagespeed/jmarantz-log-slow-file-ops
ignore errors about slow file operations
2015-07-31 17:01:39 -04:00
Joshua Marantz 8bac32c669 ignore errors about slow file operations, which can occur when running valgrind tests 2015-07-31 16:57:20 -04:00
Jeffrey Crowell 4bef2af22c Merge pull request #995 from pagespeed/crowell-disable-sendfile
add test servers for sending x-sendfile and x-accel-redirect
2015-07-23 17:34:58 -04:00
Jeffrey Crowell 52bd966edd add test servers for sending x-sendfile and x-accel-redirect 2015-07-23 13:34:25 -04:00
Jeff Kaufman 0f7a1f4503 Merge pull request #994 from pagespeed/jefftk-allow-script-variables
config: whitelist a few more directives for script variables
2015-07-23 10:36:57 -04:00
Jeff Kaufman 7f477d6575 config: whitelist a few more directives for script variables
When configuring downstream caching if you have an origin with multiple caches in front of it you might want to choose how you handle requests in response to which cache you're getting them from.  Whitelist DownstreamCachePurgeLocationPrefix, DownstreamCachePurgeMethod, and DownstreamCacheRewrittenPercentageThreshold for scripting so this is possible.
2015-07-22 10:32:41 -04:00
Jan-Willem Maessen cc10f15f53 Fix pagespeed_libraries_generator.sh to fetch pagespeed_libraries.conf from github rather than svn. 2015-07-09 10:18:51 -04:00
Jeffrey Crowell 9ee745c2ef Revert "temporarily comment tests using modpagespeed.com"
This reverts commit 5337e4b558.

closes #984
2015-07-07 13:15:33 -04:00
Jeffrey Crowell 5337e4b558 temporarily comment tests using modpagespeed.com
revert this commit when modpagespeed.com is back up
2015-07-06 12:36:44 -04:00
jmarantz b31bf7b090 Merge pull request #967 from pagespeed/jmarantz-psoff-dir-on
nginx system test changes to repro issue https://github.com/pagespeed…
2015-05-19 11:12:14 -04:00
Joshua Marantz 8464a00a77 nginx system test changes to repro issue https://github.com/pagespeed/mod_pagespeed/issues/1077 2015-05-18 09:46:12 -04:00
Jeff Kaufman b048ceb858 Merge pull request #966 from pagespeed/jefftk-doneandsetheaders
Handle DoneAndSetHeaders() new second argument that wants to know whe…
2015-05-15 10:33:32 -04:00
Jeff Kaufman 0fbdf3ee97 Handle DoneAndSetHeaders() new second argument that wants to know whether the response is complete. 2015-05-14 15:26:10 -04:00
Jeffrey Crowell a9d85960b5 add psol tar.gz to gitignore 2015-05-13 11:57:32 -04:00
Jeffrey Crowell cd19284062 initialize uninitialized variables. 2015-04-01 15:45:22 -04:00
Jeffrey Crowell c2a756049e add support for nginx 1.7.11 --with-threads 2015-04-01 15:10:26 -04:00
Maks Orlovich 6b2999dfd4 Merge pull request #944 from pagespeed/morlovich-api-adjust-InitiatePropertyCacheLookup
Adjust to API change to InitiatePropertyCacheLookup
2015-04-01 14:08:33 -04:00
Maks Orlovich 5658c20327 Adjust to API change to InitiatePropertyCacheLookup
The last argument was not actually used, and hence was removed.
2015-03-30 17:02:58 -04:00
Jeffrey Crowell ec2dea84fe Merge pull request #943 from pagespeed/crowell-rm_unused_variable
move 'type' variable to inside an #if statement
2015-03-30 14:34:48 -04:00
Jeffrey Crowell e206e871aa move 'type' variable to inside an #if statement
removes an unused variable when compile without NGX_DEBUG, allows for
building with -Werror.
2015-03-30 14:33:33 -04:00
Jeff Kaufman f4fd9a3f7c Merge pull request #935 from pagespeed/jefftk-system-public
system/public/ was moved to system/, update our references.
2015-03-18 17:04:21 -07:00
Jeff Kaufman cf88925f1e system/public/ was moved to system/, update our references. 2015-03-13 14:38:16 -04:00
Jeff Kaufman 5ea8fb9f3e Merge pull request #934 from pagespeed/jefftk-automatic-moved
Moved `automatic/` into `pagespeed/` and got rid of the `public/` hierarchy.
2015-03-13 10:44:08 -04:00
Jeff Kaufman cd31a6b129 Move automatic/public to automatic/. 2015-03-13 09:59:52 -04:00
Jeff Kaufman 137792e88f Change references from net/instaweb/automatic to pagespeed/automatic. 2015-03-13 09:30:14 -04:00
Jeffrey Crowell 91cd587e68 Merge pull request #932 from pagespeed/crowell_rm-test-grep
rm "unexpected response" grep from system test
2015-03-05 14:42:05 -05:00
Otto van der Schaaf e9608b03b7 Merge pull request #931 from pagespeed/oschaaf-trunk-tracking-native-fetcher-more-fixes
native-fetcher: fixes
2015-03-05 20:35:21 +01:00
Jeffrey Crowell 6e1a9a73a5 rm "unexpected response" grep from system test 2015-03-05 14:02:55 -05:00
Otto van der Schaaf 3875acf392 native-fetcher: fixes
- Native fetching broke in https://github.com/pagespeed/ngx_pagespeed/pull/925
  Make changes so we can do early-stage fetches in the startup process
  to fix that.
- Properly cancel out any pending fetches upon ShutDown()
- Decline fetching after ShutDown(), decline fetching when Init()
  failed.
2015-03-05 14:43:29 +01:00
Jeffrey Crowell 4dd70b40ef Merge pull request #925 from pagespeed/crowell_rconfig
Port remote configuration option to nginx.
2015-03-04 13:26:04 -05:00
Jeffrey Crowell 88d9b5241d Merge remote-tracking branch 'origin/trunk-tracking' into crowell_rconfig 2015-02-25 16:47:48 -05:00
Otto van der Schaaf 23905f8ce9 Merge pull request #922 from pagespeed/oschaaf-trunk-tracking-native-fetcher-fixes
native-fetcher: fix a few bugs
2015-02-25 21:13:02 +01:00
Otto van der Schaaf effe857083 native-fetcher: Fix a few bugs
- Add handling for header only responses
- Fixup nginx i/o handling
- Fix issues in parser state
- Revert timeout for native fetcher dns resolve to 10 seconds
- Ignore warning that gets logged with this change in tests during
  fetching from a host that refuses connections.

Should help stabilizing (valgrind) test runs some more.
2015-02-25 21:03:01 +01:00
Jeffrey Crowell 599a3bca5c update to match apache for hostnames 2015-02-24 17:36:08 -05:00
Jeffrey Crowell c26313e7ab Port remote configuration option to nginx. 2015-02-23 11:25:17 -05:00
Otto van der Schaaf bcba22dd95 Merge pull request #919 from pagespeed/oschaaf-trunk-tracking-native-fetcher-pull-755
Call async_fetch_->Done after all usages.
2015-02-18 13:38:17 +01:00
Otto van der Schaaf 1ea7e3e568 Merge pull request #917 from pagespeed/oschaaf-trunk-tracking-native-fetcher-deflake
native-fetcher: bump dns timeout to deflake running the tests
2015-02-17 21:27:32 +01:00
Jeff Kaufman 34341251f6 Merge pull request #908 from pagespeed/oschaaf-trunk-tracking-shutdown-system-test-failure
shutdown: fix system test failure in error.log sanity check
2015-02-17 13:28:56 -05:00
Vasily Chekalkin d1f2a43a71 Call async_fetch_->Done after all usages.
AsyncFetch::Done will delete itself. Accessing
async_fetch_->extra_respond_headers() will crash nginx.
2015-02-17 12:18:30 +01:00
Otto van der Schaaf 58b1264745 native-fetcher: bump dns timeout to deflake running the tests
Nginx sometimes receives an expected response from 8.8.8.8 when
resolving host names, and the subsequent retry doesn't finish up
in 10 seconds. Bumping the timeout helps, but does not fully
explain why nginx is sometimes receiving an unexpected response.
I'll create a separate issue for investigating that.
2015-02-17 11:05:34 +01:00
Otto van der Schaaf 8b6fdf56ef shutdown: fix system test failure in error.log sanity check
- Should shut down with a clean valgrind and sane logging for the
  current test workload.
- Minor cleanup
2015-02-13 21:00:43 +01:00
Otto van der Schaaf 93d70feb3b Merge pull request #907 from pagespeed/oschaaf-trunk-tracking-test-reload
configuration-reload-test: wait for the new worker to get ready
2015-02-12 20:05:27 +01:00
Otto van der Schaaf 62c8947b2d configuration-reload-test: wait for the new worker to get ready
After sending a SIGHUP, wait for the new worker process with the
new configuration to handle further requests, or else the tests
running after that might get confused when the new worker becomes
active with fresh shared mem statistics and shared mem cache.
2015-02-12 18:08:18 +01:00
Otto van der Schaaf 22749d7222 Merge pull request #906 from pagespeed/oschaaf-trunk-tracking-module-position
module-position: optional switch to install at HTTP_AUX_FILTER_MODULES
2015-02-12 17:09:23 +01:00
Otto van der Schaaf a8141eadd3 module-position: optional switch to install at HTTP_AUX_FILTER_MODULES
This change adds a flag to optionally position the module at HTTP_AUX_FILTER_MODULES
instead of just in front of the gzip module. Doing so allows header module(s) to
fully manipulate any response headers before they are send to the user-agent.
With https://github.com/pagespeed/ngx_pagespeed/pull/880, SSI no longer hangs,
and other modules using subrequests should not do so either. SSI subrequests are
not optimized when ngx_pagespeed runs at HTTP_AUX_FILTER_MODULES, so the test for
it is added to the expected failures when the tests are run for this module position.

To build with the module respositioned:
  POSITION_AUX=true ./configure ......
The same variable can be set before running the system tests, in which case it will
perform additional header tests and add the SSI test to the expected failures.
2015-02-12 16:23:11 +01:00
Otto van der Schaaf 2d28ff38e8 Merge pull request #899 from pagespeed/oschaaf-trunk-tracking-shutdown
trunk-tracking-shutdown: improve shutdown code
2015-02-10 23:52:33 +01:00
Otto van der Schaaf d7f1c0dc48 Shutdown: improve shutdown handling
- Fix valgrind errors
- Add a test to make sure all logged output looks sane by whitelisting
  current errors/warnings.
- Stop our nginx test instances after we are done testing.
- Add tests for shutting down and reloading configuration under high
  load (depends on ab).
- Reduce the number of keepalive requests in the keepalive tests to speed
  up test runs.
- Fix exiting with open file descriptors, fix cleanup in nginx's cache
  manager/loader processes
- Attempt to finish up queued up NgxBaseFetches/requests on shutdown/reload
- Under valgrind the blocking rewrite started failing after adding a test
  for reloading configuration under high load.
  I've added it to the expected failures for valgrind, looking into this
  is up next.
- Decline in ps_resource_handler when nginx is quitting. This makes us
  more reliable on continued stress during shutdown/reload.
2015-02-10 23:13:44 +01:00
Jeffrey Crowell 737e9396f5 Merge pull request #892 from pagespeed/crowell-fix-888
Replace CHECK with return failure and log.
2015-01-30 10:28:04 -05:00
Jeffrey Crowell 81029dafa6 Replace CHECK with return failure and log.
Fixes #888 along with
https://code.google.com/p/modpagespeed/source/detail?r=4533
2015-01-30 10:23:00 -05:00
Otto van der Schaaf 001cd2dc4c Merge pull request #889 from pagespeed/oschaaf-trunk-tracking-content-handler-error-responses
content-handling-errors: fall back to nginx's default handling
2015-01-27 16:50:04 +01:00
Otto van der Schaaf 3efebb7948 content-handling-errors: fall back to nginx's default handling
This change passes on non succesful status codes for pagespeed
resources and other places where we act as a content handler to
nginx. This has two benefits:
- Instead of a blank page, the user agent receives a formatted
  and (hopefully customized and informative) response.
- Header modules are able to operate on that response, which was
  requested in https://github.com/pagespeed/ngx_pagespeed/issues/612#issuecomment-58855816
2015-01-26 22:13:15 +01:00
Otto van der Schaaf 02b67b79ad Merge pull request #885 from pagespeed/oschaaf-trunk-tracking-release-early
Release base fetch early, eliminate write_pending and fetch_done
2015-01-26 16:46:30 +01:00
Otto van der Schaaf d0858790e4 Merge pull request #884 from pagespeed/oschaaf-trunk-tracking-base-fetch
base-fetch: prevent unused constructions and prop. cache lookups
2015-01-23 20:09:45 +01:00
Otto van der Schaaf 4d945b1c59 Release base fetch early, eliminate write_pending and fetch_done
Get rid of write_pending & fetch_done flags on the request context.
Assume that having ctx->base_fetch set means we have outstanding
work and thus we are not done yet, for simplicity.
This also means we'll release the base fetch earlier which seems
like a good idea to me.
2015-01-23 15:07:14 +01:00
Otto van der Schaaf 7d965aced7 Merge pull request #880 from pagespeed/oschaaf-trunk-tracking-run-posted-requests
posted-requests: run posted requests when appropriate
2015-01-21 19:47:13 +01:00
Otto van der Schaaf a5411a1c7c base-fetch: prevent unused constructions and prop. cache lookups
- Don't construct `NgxBaseFetch` instances and call `Done(false)` later when it turns out it wasn't needed.
- Track the purpose of the base fetch instead of just wether it is an IPRO lookup or not for more informational tracing
  as well as avoiding constructing base fetches when their purpose isn't know yet.
- Don't initiate a property cache lookup when we won't need it (`ProxyFetchFactory::InitiatePropertyCacheLookup`)
- Improve IPRO handling of `NgxBaseFetch` and make it clearer. Indicate we want to supress further events when the
  base fetch was used to lookup an IPRO url, and the result was not indicative of something we can respond with to the
  browser.
- Remove unused `RequestRouting` constants
2015-01-20 02:19:47 +01:00
Otto van der Schaaf 8a1260a1d1 posted-requests: run posted requests when appropriate
Request termination code relies on posted requests being run.
One of the things this fixes is that we won't hang when configured
to run before the SSI module.

Avoids trouble when changing the module order, which helps
https://github.com/pagespeed/ngx_pagespeed/issues/612
2015-01-19 10:28:00 +01:00
Otto van der Schaaf f2e7b15d9c Merge pull request #879 from pagespeed/oschaaf-trunk-tracking-server-header
server-header: improve handling of server header
2015-01-17 20:28:34 +01:00
Otto van der Schaaf 5bc61a7092 server-header: improve handling of server header
- Fixes an issue in the html flow that would prevent overriding the
value of the 'Server' response-header.
- Add tests that ensure we emit a single and correct server header
in all flows when not overriding it.
- Add tests that ensure overriding the 'Server' response header
works. The resource and IPRO flow are added to the expected failures
as those are not working yet (and will be adressed in a follow-up).

Fixed https://github.com/pagespeed/ngx_pagespeed/issues/864 (html flow)
2015-01-17 20:27:45 +01:00
Otto van der Schaaf 03819f4e4a Merge pull request #876 from pagespeed/oschaaf-single-fd-fixed
Oschaaf single fd fixed
2015-01-16 15:53:06 +01:00
Otto van der Schaaf 7ef61d2580 base-fetch-leak: Shut down NgxEventConnection before deleting it
Shutdown will drain the pipe and process the last events which
will give nginx the opportunity to run the cleanup handlers on the
associated requests.
2015-01-10 22:45:04 +01:00
Otto van der Schaaf a73c096950 Revert "Merge pull request #872 from pagespeed/jefftk-revert-834"
This reverts commit 7bd90f7b3a, reversing
changes made to 58228564dd.
2015-01-10 22:07:21 +01:00
Jeff Kaufman 7bd90f7b3a Merge pull request #872 from pagespeed/jefftk-revert-834
Revert "NgxConnection: single event mechanism
2015-01-09 10:25:12 -05:00
Jeff Kaufman 73981ffe1a Revert "NgxConnection: single event mechanism for NgxFetch and NgxBaseFetch"
This reverts commit 5dfe42f3d3.
2015-01-08 13:02:19 -05:00
Jeff Kaufman 58228564dd Merge pull request #869 from pagespeed/jefftk-system-moved
mod_pagespeed moved the location of the system directory; update our includes
2015-01-06 09:50:11 -05:00
Jeff Kaufman 340c86a49e mod_pagespeed moved the location of the system directory; update our includes 2015-01-06 09:22:56 -05:00
Otto van der Schaaf abdafc7aa4 Merge pull request #834 from pagespeed/oschaaf-single-pipe2
NgxConnection: single event mechanism for NgxFetch and NgxBaseFetch
2014-12-30 21:52:07 +01:00
Jan-Willem Maessen 8cf10873d1 Merge pull request #863 from pagespeed/jmaessen-ngx-message-handler-fix
Make ngx_message_handler work with new message_handler api.
2014-12-19 16:13:26 -05:00
Jan-Willem Maessen 2496716e36 Make ngx_message_handler work with new message_handler api. 2014-12-19 15:11:55 -05:00
Jeff Kaufman af364344e9 Merge pull request #862 from pagespeed/jefftk-rmdir
testing: give '-p' to mkdir
2014-12-17 12:55:44 -05:00
Jeff Kaufman 9da45910c7 rm won't remove the containing directory if a file is removed out from under it, which means the directory will still be there but will be empty. This is not a problem, so pass '-p' to not fail on already existing directories. 2014-12-17 12:50:23 -05:00
Otto van der Schaaf 5dfe42f3d3 NgxConnection: single event mechanism for NgxFetch and NgxBaseFetch
Abstract the pipe communication into NgxEventConnection, for reuse
by NgxBaseFetch and NgxUrlAsyncFetcher.

Based on Chai's earlier work, but with a few fixes discovered
while working on this and SPDY module compatibility

- Uses less file descriptors, I expect this to be faster but need
  measurement is needed to back that.
- Fixed NgxUrlAsyncFetcher actually shutting down its fetchers.
- Fixes a bug where we wouldn't clean idle pooled NgxConnections.
- Fixes a bug for requests that are finalized mid-IPRO lookup.
- Makes us use ngx_handle_read_event/ngx_del_event
2014-12-14 02:29:40 +01:00
Jeff Kaufman bff15040be Merge pull request #857 from pagespeed/jefftk-upstream-check-failure-function
Upstream the change to check_failures_and_exit, moving it to mod_pagespeed
2014-12-04 15:42:31 -05:00
Jeff Kaufman 3c5c5076de Upstream the change to check_failures_and_exit, moving it to mod_pagespeed 2014-12-04 13:22:13 -05:00
Jeff Kaufman eab4f8672f Merge pull request #852 from pagespeed/jefftk-move-tests-to-system
Move duplicate tests from the nginx-specific system test to system
2014-12-02 20:12:52 -05:00
Jeff Kaufman 852e376130 Move duplicate tests from the nginx-specific system test to system/system_test
As system/system_test.sh is in the mod_pagespeed repo, this is just a bunch of
deletes.
2014-12-02 15:11:23 -05:00
Jeff Kaufman b7529a8d9a Merge pull request #855 from pagespeed/jefftk-fix-tempdir
Rework parallization separation
2014-12-02 13:34:03 -05:00
Jeff Kaufman 5dd93fffae Rework parallization separation 2014-12-01 10:49:08 -05:00
Jeff Kaufman 48d23f10ba Merge pull request #851 from pagespeed/jefftk-fix-url-purging
Fix error with url cache purging test.  Followup to #850.
2014-11-17 11:25:03 -05:00
Jeff Kaufman f924bc72d9 Fix error with url cache purging test. Followup to #850. 2014-11-17 11:19:51 -05:00
Otto van der Schaaf 1aff187d0e Merge pull request #850 from pagespeed/oschaaf-trunk-tracking-script-filters-test
script-filters: Add a test for modifying filters via script variables
2014-11-14 16:03:22 +01:00
Jeff Kaufman 3b64df255a Merge pull request #849 from pagespeed/jefftk-prioritize-critical-css-test
testing: allow the prioritize_critical_css post test to fail
2014-11-14 10:02:49 -05:00
Otto van der Schaaf 0eeeca6e47 script-filters: Add a test for modifying filters via script variables
As requested via https://github.com/pagespeed/ngx_pagespeed/pull/822
2014-11-14 15:56:13 +01:00
Jeff Kaufman 6f68ba2f68 testing: allow the prioritize_critical_css post test to fail 2014-11-14 08:56:37 -05:00
Otto van der Schaaf e6e70c32a8 Merge pull request #822 from pagespeed/oschaaf-trunk-tracking-script-filters
script-filters: Allow using script variables in Enable/DisableFilters
2014-11-06 22:35:44 +01:00
Jeffrey Crowell a3e20a05e2 Merge pull request #846 from pagespeed/oschaaf-trunk-tracking-conf-multi-typo
NGX_CONF_MULTI: Typo
2014-11-04 13:46:55 -05:00
Otto van der Schaaf e28255e2ef NGX_CONF_MULTI: Typo
Fix accidental double pipe symbol.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/843
2014-11-04 13:29:49 +01:00
Otto van der Schaaf 10ac8ae4a3 Merge pull request #798 from pagespeed/oschaaf-trunk-tracking-conf-multi
older-nginx-versions: Add NGX_CONF_MULTI to ps_command flags.
2014-10-30 15:13:27 +01:00
Jeffrey Crowell 1b3ca08e22 Merge pull request #841 from pagespeed/crowell-tengine-stable-support
Check type of resolver_ctx->addrs.
2014-10-29 14:59:51 -04:00
Jeffrey Crowell de5bc5d943 Check type of resolver_ctx->addrs.
Check the type of resolver_ctx->addrs and make sure that it is
ngx_addr_t* instead of in_addr_t*. addresses issue #839
2014-10-29 14:49:55 -04:00
Otto van der Schaaf afd0f01686 script-filters: Allow using script variables in Enable/DisableFilters
To support a non-evil way (if-in-location) of tuning SPDY specific
configuration, allow scripting of Enable/DisableFilters in nginx.conf
2014-10-10 17:33:44 +02:00
Otto van der Schaaf 0cdb81fab4 Merge pull request #795 from pagespeed/oschaaf-native-fetcher-remove-check
native-fetcher: remove a DCHECK that possibly fires on shutdown.
2014-10-06 17:04:56 +02:00
hillsp b492d3966e Merge pull request #811 from pagespeed/cheesy-device-matching
Support minor PSOL API change for matches_device_type
2014-09-22 17:38:06 -04:00
Steve Hill 232c05a81d Merge remote-tracking branch 'origin/trunk-tracking' into cheesy-device-matching 2014-09-19 18:17:20 -04:00
Steve Hill adbe2cb359 Remove unit tests; They are now in system_test.sh 2014-09-19 18:14:18 -04:00
Jeffrey Crowell 88370cf54d Merge pull request #809 from pagespeed/crowell-update-config
Merge config from 1.9.32.1
2014-09-19 10:47:08 -04:00
Jeffrey Crowell b43a973071 Merge config from 1.9.32.1 2014-09-19 10:30:38 -04:00
Steve Hill a524127d49 PSOL API change and unit tests for matches_device_type 2014-09-18 18:22:46 -04:00
Otto van der Schaaf 53a6de6da8 Merge pull request #797 from pagespeed/oschaaf-finalized-requests-fix
connection_read_handler: fix potential double free
2014-09-15 16:26:29 +02:00
Otto van der Schaaf 66f1b9aa9b older-nginx-versions: Add NGX_CONF_MULTI to ps_command flags.
Older nginx versions don't allow 'pagespeed' configuration
directives to appear in blocks other then http{} without it.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/786
2014-09-14 09:19:13 +02:00
Otto van der Schaaf 6903286aa4 connection_read_handler: fix potential double free
In connection_read_handler(), make sure we act accordingly when
r->connection->error is set (indicating the the current request has
been finalized).

Reproduction of what happens when we don't: enable IPRO+SPDY, and
rapidly refresh a page with chrome. These rapid abortions will
eventually trigger a segfault/hang/misc bad behaviour.
2014-09-13 16:30:34 +02:00
Otto van der Schaaf 46dc39f5a9 Merge pull request #794 from pagespeed/oschaaf-ipro-race
IPRO: Fix a race in processing writes() from NgxBaseFetch
2014-09-12 16:33:29 +02:00
Otto van der Schaaf 7d8fefe780 native-fetcher: remove a DCHECK that possibly fires on shutdown. 2014-09-11 23:33:22 +02:00
Otto van der Schaaf 43d1706e2f IPRO: Fix a race in processing writes() from NgxBaseFetch
For FetchInPlaceResource, NgxBaseFetch would send two bytes down its
pipe, one upon HeaderComplete() and one upon HandleDone(). We need
only one to resume processing on the nginx side.

There is a race between ps_connection_read_handler() and processing
of the byte send by NgxBaseFetch::HandleDone().
ps_connection_read_handler() clears the pipe when the request is
finalized, and also drains it on each event - so two writes could be
processed as one when lucky, masking the problem).

One concrete problem this solved for me was that SPDY + IPRO +
proxy_pass would segfault, hang, and/or pass on 5xx/404 responses
from IPRO lookup fetches to the browser, next to alerts about
r->count being zero in nginx's error.log

Might fix https://github.com/pagespeed/ngx_pagespeed/issues/788
Fixes https://github.com/pagespeed/ngx_pagespeed/issues/792
2014-09-11 23:14:41 +02:00
Otto van der Schaaf 622d088a3e Merge pull request #790 from pagespeed/oschaaf-trunk-tracking-native-fetcher-keepalive
native fetcher: Support http keep-alive
2014-09-05 17:29:22 +02:00
Otto van der Schaaf 0290f52a88 native fetcher: Support http keep-alive
Based on @dinic his work, add keep-alive support for the native fetcher.
Adds a new option, usable at the http{} level in configuration:

pagespeed NativeFetcherMaxKeepaliveRequests 50;

The default value is 100 (aligned to nginx). Setting the value to 1 turns off
keep-alive requests altogether).

Most notable changes:
- Request keep-alive by adding the appropriate request header
- Fixes connections getting reused while they are servicing other requests:
- Remove connection from the pool of available connections for keepalive when applicable
- Disable keepalive in more appropriate situations
- Response parsing fixes
- Remove connections that timeout from the k.a. pool
- Add a few sanity (D)CHECKS
- Emit debug messages for traceability
- Fix for ignoring ipv6 addresses returned from dns queries when ipv6 is enabled.
- Bump the fetch timeout in test configuration to deflake tests that require dns
  lookups (which will be done via 8.8.8.8 currently for the native fetcher)
2014-09-05 17:23:16 +02:00
Maks Orlovich c94146a54d Merge pull request #791 from pagespeed/morlovich-trunk-tracking-remove-deprecated-headers
Remove use of deprecated forwarding headers
2014-09-04 16:06:52 -04:00
Maks Orlovich f3a1cb6cf4 Remove use of deprecated forwarding headers 2014-09-04 09:16:05 -04:00
jmarantz 5a23347e64 Merge pull request #785 from pagespeed/jmarantz-error-option-format
Implement NgxServerContext::FormatOption so we can indicate nginx formatting in error messages
2014-08-29 16:32:43 -04:00
Joshua Marantz 7ce289346a Override the method used to specify the format for conf files, so we can put an accurate error message in the admin GUI, and test it 2014-08-29 09:13:43 -04:00
jmarantz 6b4a9dc487 Merge pull request #784 from pagespeed/jmarantz-fgrep-for-counts
use fgrep for counting ".pagespeed."
2014-08-27 09:47:46 -04:00
Joshua Marantz a3f2e4766c use fgrep for counting ".pagespeed.", rather than grep with backslashed dot, which matches too much 2014-08-26 15:02:10 -04:00
jmarantz ab0a5e4b65 Merge pull request #782 from pagespeed/jmarantz-start-test-resets-wget-args
Assume WGET_ARGS is cleared on every start_test
2014-08-23 13:20:34 -04:00
Joshua Marantz a458a65d4e Update system test to be compatible with a helper-script update that makes start_test clear WGET_ARGS, making test stanzas more independent 2014-08-20 12:59:04 -04:00
Jeff Kaufman d00911b00f Merge pull request #775 from pagespeed/jefftk-clearer-test-flake-error
testing: make it clearer why test flake in Issue #774 happens
2014-08-14 11:34:50 -04:00
Jeff Kaufman ed80427ae6 Merge pull request #761 from pagespeed/jefftk-adding-comments
Add some comments and a few style fixes.
2014-08-14 10:29:22 -04:00
Jeff Kaufman f556ca4926 Add some comments and a few style fixes. 2014-08-14 09:52:13 -04:00
Jeff Kaufman cad618dff7 testing: make it clearer why test flake in Issue #774 happens 2014-08-13 13:53:22 -04:00
Jeff Kaufman a906411367 Merge pull request #773 from pagespeed/jefftk-nginx-message-color
testing: direct port of r4146 to fix message color issue
2014-08-13 10:51:37 -04:00
Jeff Kaufman e6c5bc1b2e testing: direct port of r4146 to fix message color issue 2014-08-13 10:13:13 -04:00
Otto van der Schaaf d6d3b90ea3 Merge pull request #769 from pagespeed/oschaaf-large-beacon-posts
beacon response body processing from temp file
2014-08-12 17:57:34 +02:00
Otto van der Schaaf d7afd2acbc beacon response body processing from temp file
Add support for processing beacon posts with data sizes that exceed
the default or configured client_body_buffer_size, plus a system test
to ensure it.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/752
2014-08-12 07:46:30 +02:00
Maks Orlovich 05f6993801 Merge pull request #772 from pagespeed/morlovich-fix-metadata-form-test
Port over test adjustment.

This is just a straight port of relevant portion of https://code.google.com/p/modpagespeed/source/detail?r=4140
2014-08-11 16:45:32 -04:00
Maks Orlovich fe63bbf53f Port over test adjustment. 2014-08-11 16:26:20 -04:00
Otto van der Schaaf c7aa72d9c5 Merge pull request #767 from pagespeed/oschaaf-issue-757
rewriting-posts: Support POST responses for html
2014-08-07 16:28:51 +02:00
Otto van der Schaaf 8f6bb0c9e3 rewriting-posts: Support POST responses for html
Allow rewriting html responses to POST requests

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/757
2014-08-07 16:02:23 +02:00
Otto van der Schaaf 84f2a1884e Merge pull request #765 from pagespeed/oschaaf-trunk-tracking-script-support
script-variables: Support LoadFromFileXXX
2014-08-05 16:45:19 +02:00
Otto van der Schaaf da83f73f19 script-variables: Support LoadFromFileXXX
Based on 75a4481 from master.

Add support for script variables in LoadFromFileXXX configuration to trunk-tracking,
which can be enabled by adding "pagespeed ProcessScriptVariables on" in
the http{} block.
Also adds a helpful comment to ps_dollar().

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/549
Docs: https://github.com/pagespeed/ngx_pagespeed/wiki/Script-variables-in-LoadFromFile-configuration

Resolved conflicts:
	src/ngx_rewrite_driver_factory.h
	src/ngx_rewrite_options.cc
	test/nginx_system_test.sh
2014-08-05 00:51:07 +02:00
jmarantz 2bfc05b4c6 Merge pull request #763 from pagespeed/jmarantz-http-200-ok-function
use a new helper method to verify HTTP response codes are 200 OK
2014-08-04 11:00:03 -04:00
jmarantz ea9e209687 Merge pull request #764 from pagespeed/jmarantz-systest-exit-on-error
Make script execute properly in the context of 'set -e'
2014-08-04 10:04:03 -04:00
Joshua Marantz c073a3120b remove debug comments 2014-08-04 10:02:31 -04:00
Joshua Marantz 5e3b2f23a5 Make script execute properly in the context of 'set -e' 2014-08-01 09:29:08 -04:00
Joshua Marantz f41ecf4010 use a new helper method to verify HTTP response codes are 200 OK 2014-08-01 09:19:40 -04:00
Jeff Kaufman 34a62db9cf Merge pull request #760 from pagespeed/sligocki-request-context-set-options
Set options for RequestContexts in ngx_pagespeed.
2014-07-30 09:53:00 -04:00
Jeffrey Crowell b0efa9f982 Merge pull request #758 from pagespeed/crowell-debug-filter-safe-to-print
add safe_to_print on nginx rewrite options
2014-07-29 16:58:10 -04:00
Shawn Ligocki fb00ac373b Set options for RequestContexts in ngx_pagespeed. 2014-07-29 16:05:27 -04:00
Jeffrey Crowell 9550629768 add safe_to_print on nginx rewrite options 2014-07-29 14:58:06 -04:00
Shawn Ligocki 26a5deb341 Merge pull request #756 from pagespeed/sligocki-in-place-api-change
Fix InPlaceResourceRecorder constructor to remove two arguments passed in through options now.
2014-07-29 13:09:44 -04:00
Shawn Ligocki 7bcd5aadde Fix InPlaceResourceRecorder constructor to remove two arguments passed in through options now. 2014-07-28 18:02:17 -04:00
matterbury 594ba13606 Merge pull request #751 from pagespeed/matterbury-unauthorized-debug
Test the new debug messages for unauthorized domains.
2014-07-09 14:40:24 -04:00
Matt Atterbury 9d0b896737 Test the new debug messages for unauthorized domains. 2014-07-08 09:17:06 -04:00
Jud Porter 89f6465288 Merge pull request #748 from pagespeed/jud-ipv6-smoke-test
Fix smoke test on systems with ipv6 localhost
2014-07-02 13:37:23 -04:00
Jud Porter eb11cfe0cf Add ipv6 listen directives to smoke test config server blocks. 2014-07-02 10:57:40 -04:00
Jud Porter 7a0e45d025 Ignore "Hostname was NOT found in DNS cache" message generated by more recent versions of curl. 2014-07-02 10:49:23 -04:00
jmarantz 3cf731ee24 Merge pull request #743 from pagespeed/jmarantz-nginx-purge-method
Fix PURGE method support and testing to ngx_pagespeed
2014-07-01 17:44:38 -04:00
Joshua Marantz 1a4ffcf335 Fix PURGE method support and testing to ngx_pagespeed 2014-06-30 09:49:10 -04:00
Jeff Kaufman 72c7e584f7 Merge pull request #740 from pagespeed/jefftk-unused-function
Remove unused function.  Fixes #739.
2014-06-30 11:26:07 +01:00
Jeff Kaufman 08f69913dc Merge pull request #738 from pagespeed/jefftk-fix-style
style: minor fixes, mostly as a followup to #665
2014-06-27 17:15:11 -04:00
Jud Porter f2d6bcf3ac Merge pull request #742 from pagespeed/jud-exit-status
Have manual ngx_pagespeed runs return exit code 0.
2014-06-27 16:55:30 -04:00
Jud Porter 2c89815084 Have manual ngx_pagespeed runs return exit code 0. 2014-06-27 16:54:31 -04:00
Jeff Kaufman e55b062c17 Remove unused function. Fixes #739. 2014-06-27 10:22:58 -04:00
Jeff Kaufman 62ef051844 style: minor fixes, mostly as a followup to #665 2014-06-24 15:50:19 -04:00
Jeff Kaufman 36b07ca209 Merge pull request #665 from We-Amp/keesspoelstra-gzip-enable-trunk
gzip: enabling gzip on "pagespeed on"
2014-06-24 07:20:12 -04:00
Jeff Kaufman 1280cd0dfa Merge pull request #734 from pagespeed/jefftk-move-doc-to-devsite
readme: reference doc on developers.google.com instead of duplicating it
2014-06-23 10:38:43 -04:00
Jeffrey Crowell a06551a97d Merge pull request #735 from pagespeed/crowell-accept-invalid-signatures
add tests for accepting invalid signatures.
2014-06-20 16:36:42 -04:00
Jeffrey Crowell 679618f998 remove signature tests that live in automatic/system_test.sh 2014-06-20 11:24:30 -04:00
Jeffrey Crowell fb9b355715 rename REGEX to URL_REGEX in test 2014-06-20 10:56:31 -04:00
Jeffrey Crowell f71ac7dd0c add accept-invalid-signatures tests for transition to signed resources 2014-06-20 10:51:31 -04:00
Jeff Kaufman 19f479a6b6 readme: reference doc on developers.google.com instead of duplicating it. 2014-06-20 10:19:53 -04:00
xqyin 7431946d23 Merge pull request #733 from pagespeed/xqyin-refactor-message-handler3
Make NgxMessageHandler inherit to SystemMessageHandler
2014-06-20 10:17:54 -04:00
Cathy Yin 0d760dbf31 Make NgxMessageHandler inherit to SystemMessageHandler. Move SharedCircularBuffer things to SystemMessageHandler. 2014-06-19 15:56:03 -04:00
Cathy Yin e9d7b2ad01 Merge remote-tracking branch 'origin/trunk-tracking' into xqyin-refactor-message-handler2 2014-06-19 13:55:25 -04:00
jmarantz 0d89df0e80 Merge pull request #732 from pagespeed/jmarantz-cache-purge
add support for cache purge requests via GET from admin or PURGE method....
2014-06-19 13:44:27 -04:00
Cathy Yin 218d74f206 Make NginxMessageHandler inherit to a new class SystemMessageHandler. Move SharedCircularBuffer related operations there. 2014-06-19 13:06:53 -04:00
Jeff Kaufman bcefd56941 Merge pull request #720 from pagespeed/jefftk-lff-ipro
testing: a server block for testing load from file with ipro
2014-06-19 11:20:33 -04:00
Jeff Kaufman 676344bc8a testing: a server block for testing load from file with ipro 2014-06-19 10:01:33 -04:00
Joshua Marantz 7293f649d1 add support for cache purge requests via GET from admin or PURGE method. PURGE doesn't quite work yet, so we skip testing that one. 2014-06-19 09:34:40 -04:00
Jeff Kaufman 10f5093bf6 Merge pull request #731 from pagespeed/jefftk-thread-config
options: support setting NumRewriteThreads
2014-06-18 15:08:42 -04:00
Jeff Kaufman 357eb92683 options: move global option parsing to system/ 2014-06-18 15:08:08 -04:00
Jeff Kaufman a6c6d13392 Support setting NumRewriteThreads and NumExpensiveRewriteThreads
Several rewrite driver factory options are duplicated between apache and nginx.  Instead of duplicating this one too, a PSOL change moves them into system/, and this change takes advantage of that move.
2014-06-16 11:25:39 -04:00
xqyin 9007e582ad Merge pull request #727 from pagespeed/xqyin-refactor-admin-site
Change SystemServerContext::kStatistics to AdminSite::kStatistics
2014-06-11 14:55:42 -04:00
Cathy Yin 1ca04d514c Change SystemServerContext::kStatistics to AdminSite::kStatistics. 2014-06-11 14:01:15 -04:00
Kees Spoelstra 8e08b2b7e0 this adds the following configuration on "pagespeed on"
gzip on;
gzip_proxied any;
gzip_vary on;
gzip_types application/ecmascript;
gzip_types application/javascript;
gzip_types application/json;
gzip_types application/pdf;
gzip_types application/postscript;
gzip_types application/x-javascript;
gzip_types image/svg+xml;
gzip_types text/css;
gzip_types text/csv;
gzip_types text/html;
gzip_types text/javascript;
gzip_types text/plain;
gzip_types text/xml;
gzip_http_version 1.0;

If any explicit gzip configuration is detected the gzip configuration
set by pagespeed is rolled back completely and the explicit gzip
configuration is used.

To enable/disable gzip with pagespeed the following commands can be used:

pagespeed gzip on;
pagespeed gzip off;

We test the nesting of the gzip configuration (pagespeed gzip on/off and
pagespeed on/off)
Ideally we need to test all the content types as well and the rollback in
case of an explicit gzip configuration, but to do this we need to be able
to map a custom directory into the nginx tests this and seperate nginx
config files.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/238
2014-06-11 17:40:52 +02:00
Kees Spoelstra ad1a1594d6 this adds the following configuration on "pagespeed on"
gzip on;
gzip_proxied any;
gzip_vary on;
gzip_types application/ecmascript;
gzip_types application/javascript;
gzip_types application/json;
gzip_types application/pdf;
gzip_types application/postscript;
gzip_types application/x-javascript;
gzip_types image/svg+xml;
gzip_types text/css;
gzip_types text/csv;
gzip_types text/html;
gzip_types text/javascript;
gzip_types text/plain;
gzip_types text/xml;
gzip_http_version 1.0;

If any explicit gzip configuration is detected the gzip configuration
set by pagespeed is rolled back completely and the explicit gzip
configuration is used.

To enable/disable gzip with pagespeed the following commands can be used:

pagespeed gzip on;
pagespeed gzip off;
2014-06-11 17:28:25 +02:00
jmarantz d5e37d2d2e Merge pull request #726 from pagespeed/jmarantz-remove-spew-and-extra-read
make check-from greps be silent, and remove extra 'read'
2014-06-11 11:28:21 -04:00
Joshua Marantz 4bceb402a6 make check-from greps be silent, and remove extra 'read' that was causing smoke tests to apparently hang 2014-06-11 10:48:42 -04:00
Jeffrey Crowell 80a50fe9d8 Merge pull request #724 from pagespeed/crowell-signed-urls
signed-urls tests added.
2014-06-10 17:16:30 -04:00
Jeffrey Crowell 28192a509e update nginx_system_test to use signed resources. 2014-06-10 16:41:41 -04:00
Jeff Kaufman 9331815350 Merge pull request #721 from pagespeed/oschaaf-lff-ipro-trunk-tracking
ipro-lff: Prevent handing out 200/OK when we can't rewrite in place
2014-06-05 15:22:51 -04:00
Otto van der Schaaf 727d339dfd ipro-lff: Prevent handing out 200/OK when we can't rewrite in place
PSOL change for in_place_rewrite_context.cc
- Reorder setting the status code so we actually change the
  ResponseHeaders that we are using to serve
- Prevent non-error http status codes from being served up.

As noted by @jeffkaufman, to prevent a potential lifetime issue with
ResponseHeaders, remove the call to ps_release_base_fetch() in
ps_decline_request().

PSOL patch:
```diff
--- ../rewriter/in_place_rewrite_context.cc	(revision 4020)
+++ ../rewriter/in_place_rewrite_context.cc	(working copy)
@@ -127,9 +127,20 @@
       // to us.
       streaming_ = false;
       set_request_headers(NULL);
+      // If we cannot rewrite in-place, we should not serve a 200/OK.
+      // Serve kNotFound instead to fall back to the server's native
+      // method of serving the url and indicate we don't want it recorded
+      // either.
+      // TODO(oschaaf): When the resource is loaded via LoadFromFile,
+      // this code gets repeatedly hit for the same url. That might
+      // become a drag when the file in question is very large and popular.
+      // Marking urls that end up in this flow as not cachable in the http cache
+      // at this point had no effect (for the LoadFromFile flow at least).
+      if (!response_headers()->IsErrorStatus()) {
+	response_headers()->set_status_code(HttpStatus::kNotFound);
+      }
       set_response_headers(NULL);
       set_extra_response_headers(NULL);
-      response_headers()->set_status_code(HttpStatus::kNotFound);
       SharedAsyncFetch::HandleDone(false);
     }
   }
```
2014-06-05 15:46:53 +02:00
jmarantz b3e5297dc3 Merge pull request #717 from pagespeed/jmarantz-psol-library-from-env-var2
Allow the path to the PSOL library to be specified by an env var.
2014-06-03 18:01:40 -06:00
Joshua Marantz 639a01015c fix indentation 2014-06-03 19:59:44 -04:00
Kees Spoelstra 29a43196e8 gzip: enabling gzip on "pagespeed on"
this adds the following configuration on "pagespeed on"
gzip  on;
gzip_proxied any;
gzip_vary on;
gzip_types application/ecmascript;
gzip_types application/javascript;
gzip_types application/json;
gzip_types application/pdf;
gzip_types application/postscript;
gzip_types application/x-javascript;
gzip_types image/svg+xml;
gzip_types text/css;
gzip_types text/csv;
gzip_types text/html;
gzip_types text/javascript;
gzip_types text/plain;
gzip_types text/xml;
gzip_http_version 1.0;

If an explicit configuration is detected the gzip configuration
set by pagespeed on is rollbacked

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/238
2014-06-03 23:29:31 +02:00
matterbury 0b20c91217 Merge pull request #718 from pagespeed/matterbury-move-redirection-tests
Move redirection tests to the common test script.
2014-06-03 11:27:16 -04:00
Matt Atterbury d654062516 Move redirection tests to the common test script. 2014-06-02 09:30:34 -04:00
Joshua Marantz b6991fd107 Allow the path to the PSOL library to be specified by an env var. This was already doc'd in a comment in 'config' but did not work. 2014-05-31 07:58:50 -04:00
Jeff Kaufman bf042f8af9 Merge pull request #715 from pagespeed/jefftk-move-contrnet-length-test
headers: content length is now tested in common code
2014-05-30 09:28:11 -04:00
Jeff Kaufman 22950666e0 headers: content length is now tested in common code 2014-05-29 15:19:58 -04:00
xqyin 96f185d472 Merge pull request #709 from pagespeed/xqyin-color-messages
Color messages in the message_history page. Add system test for this change.
2014-05-28 17:39:05 -04:00
Jeff Kaufman c9a106b4b0 readme: with 1.8 we need different default config 2014-05-28 16:33:01 -04:00
Jeff Kaufman 00080ff728 readme: 1.7.30.4 -> 1.8.31.2 2014-05-28 16:13:01 -04:00
Cathy Yin b6098ce302 Color the messages in message_history page. Add corresponding system test for this change. 2014-05-28 09:42:14 -04:00
Jeff Kaufman 36d285a354 Merge pull request #707 from pagespeed/jefftk-fix-static-asset-prefix
options: support StaticAssetPrefix
2014-05-27 11:35:39 -04:00
Matt Atterbury 149d1c7a5c Moved cookie option tests to common test script. 2014-05-27 09:59:59 -04:00
Matt Atterbury 9e9bf76164 Added system test for sticky options. 2014-05-27 09:59:59 -04:00
Matt Atterbury 09bc3b0aba Added query parameter to make the other query parameters 'sticky' by returning cookies that set them so are passed in subsequent requests. 2014-05-27 09:59:59 -04:00
Jeff Kaufman 502abb2f10 options: support StaticAssetPrefix 2014-05-23 14:09:49 -04:00
matterbury 08bdfb8c65 Merge pull request #700 from pagespeed/matterbury-sticky-options
Added query parameter to make the other query parameters 'sticky' ...
2014-05-20 14:16:47 -04:00
Matt Atterbury 8a8f62fefa Moved cookie option tests to common test script. 2014-05-19 09:27:26 -04:00
Matt Atterbury 94ab5c33f8 Added system test for sticky options. 2014-05-16 12:01:57 -04:00
Matt Atterbury 0e766e4096 Merge remote-tracking branch 'origin/trunk-tracking' into matterbury-sticky-options
if it merges an updated upstream into a topic branch.
2014-05-16 12:00:33 -04:00
Jeff Kaufman a7fdc86744 Merge pull request #701 from pagespeed/jefftk-move-settings-to-server-scope
move settings to server scope

Allow you to set `MessagesPath`, `StatisticsPath`, `AdminPath`, or `ConsolePath`  in a `server {}` block.
2014-05-12 09:34:39 -04:00
Jeff Kaufman aed13fc578 Allow admin paths to be set at server scope. 2014-05-12 09:12:52 -04:00
Matt Atterbury cd753a22a7 Added query parameter to make the other query parameters 'sticky' by returning cookies that set them so are passed in subsequent requests. 2014-05-12 08:26:32 -04:00
matterbury 6af5774ef8 Merge pull request #688 from pagespeed/matterbury-queryparams
Rename QueryParams::Parse to ParseFromUrl. Add a wrapper that takes an untrusted string.
2014-04-30 10:05:01 -04:00
Matt Atterbury 117994993a Rename QueryParams::Parse to ParseFromUrl. Add a wrapper that takes an untrusted string. 2014-04-30 09:59:34 -04:00
Jeffrey Crowell 5487b7350c Merge pull request #684 from pagespeed/crowell-requst-option-override
add ngx test support for RequestOptionOverride option
2014-04-28 13:53:41 -04:00
Jeffrey Crowell 261b602f83 add ngx test support for RequestOptionOverride option 2014-04-25 11:48:29 -04:00
Jeff Kaufman ae3cf7a425 Merge branch 'master' into trunk-tracking 2014-04-25 08:27:36 -04:00
Jeff Kaufman b4af0738a5 readme: use nginx 1.6.0 2014-04-25 08:27:26 -04:00
Jeff Kaufman ff049a55c3 Merge pull request #681 from pagespeed/jefftk-psol-dep
dependencies: include psol as a dependency
2014-04-24 14:04:24 -04:00
Jeff Kaufman 0772787ad4 dependencies: include psol as a dependency 2014-04-24 13:30:17 -04:00
jmarantz 7eedc2ce3c Merge pull request #680 from pagespeed/jmarantz-clean-proactive
clean up the conf file overrides to turn off proactive resource
2014-04-24 11:21:20 -04:00
Joshua Marantz 7af665b5dd clean up the conf file overrides to turn off proactive resource
fetching and compressed cache.  the compressed cache was ok but
proactive resource fetching consistently fails system tests in nginx
2014-04-24 11:16:27 -04:00
Jeff Kaufman 8136a15352 Merge pull request #678 from pagespeed/jefftk-update-trunk-tracking
port r3968 which is supposed to be just a test that a bug isn't present...
2014-04-23 15:46:59 -04:00
Jeff Kaufman 31024cfc24 trunk-tracking: also turn off ProactiveResourceFreshening until we fix PSOL. 2014-04-23 15:25:49 -04:00
Jeff Kaufman 703fda7eba port r3968 which is supposed to be just a test that a bug isn't present, but in ngx_pagespeed actually triggers that bug. This needs to be fixed, but is out of scope for a trunk-tracking update. 2014-04-23 14:56:25 -04:00
Jeff Kaufman d4bc40007e Merge pull request #677 from pagespeed/jefftk-update-trunk-tracking
trunk-tracking: update from r3949 to r3967
2014-04-23 14:11:50 -04:00
Jeff Kaufman f2e2ab6056 port r3966 by turning off CompressMetadataCache which breaks ipro 2014-04-23 13:22:14 -04:00
Jeff Kaufman e06a65e7e6 port 3967 which adds a fetch_until to the prioritize critical css test 2014-04-23 10:20:31 -04:00
Jeff Kaufman 3231949e03 port r3964 which handles options in request cookies 2014-04-23 10:10:48 -04:00
Jeff Kaufman f5713996f2 Merge branch 'trunk-tracking' of github.com:pagespeed/ngx_pagespeed into trunk-tracking 2014-04-23 09:15:57 -04:00
Jeff Kaufman 185632583b Merge pull request #675 from pagespeed/jefftk-update-trunk-tracking
trunk tracking: update from r3934 to r3949
2014-04-23 09:15:45 -04:00
Jeff Kaufman c5dbfa16cd trunk-tracking: fix comment 2014-04-23 09:14:58 -04:00
Jeff Kaufman 33b2e82ec6 trunk-tracking: port tests for r3948, PageSpeed=... not ModPagespeed=... 2014-04-22 17:56:09 -04:00
Jeff Kaufman b87ffce5ba trunk-tracking: port r3945 which made the location of static assets configurable 2014-04-22 17:55:57 -04:00
Jeff Kaufman 7d5fc11afd trunk-tracking: port tests for r3937, url-valued attributes overriding spec 2014-04-22 17:38:51 -04:00
Jeff Kaufman 7cba7ba4f4 trunk-tracking: port tests for r3935 which changes image lazyloading 2014-04-22 17:38:51 -04:00
Jeff Kaufman cf434f71cc trunk-tracking: port r3937 which supports custom url-valued attributes overriding spec-defined ones 2014-04-22 16:37:13 -04:00
Jeff Kaufman ba8c149a88 Merge pull request #670 from pagespeed/oschaaf-downstream-cache-headers
downstream-caching-headers: make nginx 1.5.9+ pass tests as well
2014-04-21 17:07:23 -04:00
Jeff Kaufman f5bac604a1 Merge pull request #671 from pagespeed/oschaaf-downstream-cache-test
downstream-cache-test: deflake the test
2014-04-21 10:27:53 -04:00
Otto van der Schaaf f18faa3ae1 downstream-cache-test: deflake the test
As suggested by Anupama, deflake the test by only allowing beaconing
when explitly requested by http request from tests.

Html with beacons in it will bypass the proxy cache.
2014-04-20 00:24:32 +02:00
Otto van der Schaaf 070ae2aad2 downstream-caching-headers: make nginx 1.5.9+ pass tests as well
- Fix a mistake I made in https://github.com/pagespeed/ngx_pagespeed/pull/653
  This is the primary reason the test starts failing, the base fetch
  handled `kPreserveOnlyCacheControl` in the wrong way.
- Use `ps_set_cache_control` when copying a Cache-Control header
  to nginx, as `r->headers_out.cache_control` is where modules running
  after us might expect it
- Exclude a few more lines from curl's verbose output in the keep-
  alive tests that I came accross when testing on ubuntu 13.10
  Desktop.

Note that this does not deflake the downstream cache test yet, I will
look at that in a follow-up.
2014-04-19 22:58:09 +02:00
Jeff Kaufman 674c70e32c Merge pull request #669 from pagespeed/morlovich-trunk-tracking-ssl-tests
Port over the basic HTTPS fetching test.
2014-04-17 16:36:01 -04:00
Maks Orlovich b4ef143a88 Port over the basic HTTPS fetching test. 2014-04-17 16:20:10 -04:00
Jeff Kaufman ffdc3c8fd6 Merge pull request #667 from pagespeed/jefftk-merge-master-to-tt
trunk-tracking: merge in master
2014-04-17 15:21:19 -04:00
Jeff Kaufman af10fc3ddb trunk-tracking: merge in master 2014-04-17 15:16:43 -04:00
Jeff Kaufman e9a099f9c5 Merge pull request #666 from pagespeed/jefftk-update-trunk-tracking
trunk-tracking: update from r3924 to r3934
2014-04-17 10:43:46 -04:00
Jeff Kaufman e4a2933c58 trunk-tracking: update from r3924 to r3934
There aren't actually any changes required from r3924 to r3934 but the admin
work from previous versions wasn't completely ported before.

This change:
 * adds support for /pagespeed_admin and /pagespeed_global_admin
 * removes NgxPagespeedConsoleAsyncFetch using NgxBaseFetch instead
 * adds options StatisticsPath, GlobalStatisticsPath, ConsolePath,
   MessagesPath, AdminPath, and GlobalAdminPath which allow site owners to
   control what path these are served under
 * changes /ngx_pagespeed_statistics etc from default-on to default-off,
   requiring explicit path configuration to function
 * does not fix the problem where trunk-tracking fails tests on 1.5 post #653
2014-04-17 10:10:20 -04:00
Jeff Kaufman 2601232457 Merge pull request #655 from pagespeed/oschaaf-native-fetcher-resolve-timeout
native-fetcher: fix CHECK failure on DNS timeout
2014-04-14 07:28:42 -04:00
Otto van der Schaaf a3e1810a6a Merge pull request #653 from pagespeed/oschaaf-downstream-caching-headers
downstream-caching: Fix pagespeed resource response headers
2014-04-10 21:56:01 +02:00
Otto van der Schaaf 72f3c79fec downstream-caching: Fix pagespeed resource response headers
- Make kPreserveOnlyCacheControl do what it says on the tin
- Serve pagespeed resources with the response headers computed
  by PSOL regardless of whether downstream caching is configured.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/652
2014-04-10 21:42:48 +02:00
Otto van der Schaaf 323e820fde Merge pull request #658 from pagespeed/oschaaf-configure-wnoerror
nginx-gridfs: Add configure option to build with wno-error
2014-04-09 20:38:57 +02:00
Otto van der Schaaf a9a7bf56ac Merge pull request #659 from pagespeed/jud-trunk-tracking
trunk-tracking: update from r3895 to r3924
2014-04-08 21:58:16 +02:00
Jud Porter 2358f957cb trunk-tracking: update from r3895 to r3924 2014-04-08 14:51:04 -04:00
Otto van der Schaaf 7d72a7c89a 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
2014-04-08 13:10:58 +02:00
Otto van der Schaaf 8830724580 native-fetcher: fix CHECK failure on DNS timeout
Make sure we clear the timeout event associated with resolving
a hostname in `CallbackDone()`, which would otherwise end up
calling `CallbackDone()` a second time upon firing.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/625
2014-04-06 09:17:45 +02:00
Otto van der Schaaf c2d07a8d5a Merge pull request #651 from pagespeed/morlovich-trunk-tracking-upto-r3895
trunk tracking upto r3895
2014-04-02 18:53:04 +02:00
Maks Orlovich c3bff67637 Fix improper cache key on write for IPRO of resources with PageSpeed params
We need to be writing with the base name, with params stripped.
This was causing a test to "flake" under valgrind, since with it we got
to the test showing the bug slowly enough for the entry written out by
an earlier test under proper URL to expire.
2014-04-02 18:41:08 +02:00
Maks Orlovich 5a1a29ee8b trunk-tracking: update from r3872 to r3895
Squash-merge of @morlovich's work on this.

Note that this does not yet incorprorate the new
pagespeed_admin handler from r3891
2014-04-02 18:39:08 +02:00
Jeff Kaufman 61025c5e4f if: support pagespeed directives in location if blocks 2014-03-31 10:35:05 -04:00
Otto van der Schaaf d3e7900704 Merge pull request #648 from pagespeed/jmaessen-trunk-tracking
trunk-tracking: update from r3852 to r3872
note that it will only compile against mod_pagespeed r3872 if you first patch in r3889
2014-03-28 22:37:31 +01:00
Jan-Willem Maessen 85e19c962b trunk-tracking: update from r3852 to r3872 2014-03-27 10:59:13 -04:00
Otto van der Schaaf 20fd7d18dd Merge pull request #646 from pagespeed/oschaaf-chunked-transfer
content-length: fix pagespeed/ipro resource content-lengths
2014-03-26 08:53:50 +01:00
Otto van der Schaaf 4667aa1fc3 content-length: fix pagespeed/ipro resource content-lengths
Makes life downstream easier and more efficient
2014-03-25 21:29:28 +01:00
Jeff Kaufman 6ced8c0f65 Merge pull request #641 from pagespeed/jefftk-if-block
if: support pagespeed directives in location if blocks
2014-03-25 13:16:27 -04:00
Jeff Kaufman bfaf4268cf Merge pull request #639 from pagespeed/jefftk-trunk-tracking
trunk-tracking: update from r3827 to r3852
2014-03-19 16:57:28 -04:00
Jeff Kaufman 78cf39f9b3 if: support pagespeed directives in location if blocks 2014-03-19 16:46:48 -04:00
Jeff Kaufman 215071a383 trunk-tracking: update from r3827 to r3852
* port EnrollExperiment tests.
* tricky changes to get gzip+ipro working properly.
* reduce code duplication by calling copy_response_headers_from_ngx instead
  of reimplementing it.
* port Vary: Accept test changes.
2014-03-18 16:58:50 -04:00
Jeff Kaufman 630f7d848b lint: fix lint errors 2014-03-18 10:38:58 -04:00
Huibao Lin d90245af69 trunk-tracking: merge changes in from master:
* release: prepare 1.7.30.3
* Don't call chown() when initializing config dirs unless owner != worker user.
* Update README.md
* release: build against backported change
* release: udpate version number 1.7.30.3 to 1.7.30.4
2014-03-18 10:38:28 -04:00
Jeff Kaufman f25569690a merge commit: merge 1.7.30.4 into master 2014-03-14 10:15:42 -04:00
huibaolin 707d671826 Change version 1.7.30.3 to 1.7.30.4 2014-03-14 08:16:38 -04:00
Jeff Kaufman f8b87ea436 Merge pull request #636 from pagespeed/huibao-prepare-1.7.30.4-release
release: update version number 1.7.30.3 to 1.7.30.4
2014-03-13 10:37:21 -04:00
Huibao Lin 86d840f76e release: udpate version number 1.7.30.3 to 1.7.30.4 2014-03-13 10:27:21 -04:00
Jeff Kaufman 0110d33fa7 Merge pull request #635 from pagespeed/huibao-prepare-1.7.30.4-release
release: build against backported change
2014-03-13 10:26:16 -04:00
Huibao Lin 497594ba7f release: build against backported change 2014-03-13 10:18:57 -04:00
Jeff Kaufman 336352df38 Merge pull request #633 from pnommensen/patch-2
readme: use nginx 1.4.6
2014-03-07 13:17:42 -05:00
Patrick Nommensen 0edd405eb8 Update README.md
Don't know how I missed that.
2014-03-07 10:16:43 -08:00
Jeff Kaufman d004c4d916 Merge pull request #632 from pnommensen/patch-2
1.4.5 to 1.4.6 update
2014-03-07 11:32:01 -05:00
Jeff Kaufman c754cf1be0 trunk-tracking: update from r3811 to r3927 2014-03-07 11:18:35 -05:00
Patrick Nommensen 091ef6399b version update
1.4.5 to 1.4.6 http://nginx.org/en/CHANGES-1.4
2014-03-06 23:25:13 -08:00
Jeff Kaufman 9e4d26da5e Merge pull request #629 from pagespeed/jmaessen-trunk-tracking
trunk-tracking: update from r3784 to r3811
2014-03-03 16:56:15 -05:00
Jan-Willem Maessen 027d481817 trunk-tracking: update from r3784 to r3811
The big change here is Vary: headers, which are no longer being stripped from the pagespeed response.  Take a look; it might be we want to be smart about merging these headers with the original request's Vary: headers.
2014-02-27 19:41:23 -05:00
Jeff Kaufman 67106e920e apr: call SystemRewriteDriverFactory::InitApr()
squash-merge of morlovich's #601.
2014-02-20 09:13:56 -05:00
Jeff Kaufman 9699caeab5 Merge pull request #623 from pnommensen/patch-1
Update README.md
2014-02-20 09:12:04 -05:00
Patrick Nommensen c371d516a8 Update README.md
nginx version update
2014-02-20 00:04:21 -08:00
Jeff Kaufman 207eb2d131 Merge pull request #622 from pagespeed/jefftk-trunk-tracking
trunk-tracking: update from r3770 to r3784
2014-02-19 12:58:40 -05:00
Jeff Kaufman d9e2142f31 trunk-tracking: update from r3770 to r3784
* r3772 changed the format of unauthorized resource inlining config
* r3776 changed query param handling, but due to Jud's nice work in
  #616 needed no changes.
* r3780 huibao's refactoring lets us remove some duplicate code
* r3783 changes header passing with ipro
* Also cleaned up error messages for unknown options.
2014-02-19 10:53:48 -05:00
Jeff Kaufman bf6c6c0e9b Merge pull request #621 from jart/dont-chown
Security Fix: Don't call chown() unless necessary.
2014-02-18 14:32:32 -05:00
Justine Tunney e8dd9fd3c3 Don't call chown() when initializing config dirs unless owner != worker user. 2014-02-15 22:32:55 -05:00
Jud Porter 33d006625e Merge pull request #616 from pagespeed/jud-trunk-tracking
trunk-tracking: update from r3736 to r3770
2014-02-11 16:43:33 -05:00
Anupama Dutta 2dcaa95278 trunk-tracking: update from r3736 to r3770
Updated global_only options to include the correct APACHE_CONFIG_OPTIONX directives.
Removed repeated tests for prioritize_critical_css basic functionality.
Added new tests, mostly downstream caching tests and related pagespeed.conf updates. Also added missing pagespeed.conf updates for downstream caching.
Added support for checking option scope.
2014-02-11 16:40:07 -05:00
Jeff Kaufman f5252b569a trunk-tracking: update from r3715 to r3736
Squash-merge of Jan's #608 and Otto's #611.

* r3726:
  * Updated closure compiler flags for static JS files.
* r3729:
  * Centralize parsing of FetchHttps in SystemRewriteOptions so ngx_pagespeed
    can get it too.
  * To keep the helpful error_message from SerfUrlAsyncFetcher, wire it through
    RewriteOptions as a new-fangled error_detail.
* r3735:
  * Follow-up changes for downstream caching integration with beaconing
    dependent filters: If a downstream cache rebeaconing key is configured, we
    should instrument the page only if the key present in the PS-ShouldBeacon
    header matches the one in the configuration. This allows us to send no-cache
    headers for anything that carries the right beaconing key, and continue to
    send out the original cache control headers in other cases where downstream
    caching is enabled.
* Native fetcher: fortify handling of content length (and absense).
* Native fetcher: fail when the stream terminates before having
  completely parsed the headers.
* Tests: Rename `test_filter` -> `start_test` in ngx_system_test.sh for
  a test.
* Tests: Move blockingrewrite key to the http {} block.
* Tests: Update localhost -> 127.0.0.1. The native fetcher uses
  dns to resolve, and won't be able to retreive an ip for
  localhost.
* Tests: Allow outstanding proxy fetches some time to finish
  when running under valgrind, before terminating nginx.
* Valgrind: Add suppressions to make testing a release build pass.

This pull update was extra work because the valgrind and native fetcher flows
had rotted a bit.  We need to make sure to test them with every update.
2014-01-31 10:07:36 -05:00
Jeff Kaufman 64eaa2a659 Merge pull request #602 from tcpper/fix_ngx_fetch_content_length
fix bug in NgxFetch#content_length_
2014-01-30 11:25:52 -08:00
Jeff Kaufman 4783144e7d Merge branch 'master' into trunk-tracking 2014-01-24 16:56:26 -05:00
Jeff Kaufman 83205c9c31 Merge pull request #606 from pagespeed/oschaaf-multiple-experiment-cookies
Experiments: fix sending out multiple experiment cookies
2014-01-24 13:12:27 -08:00
Otto van der Schaaf 625e762961 Experiments: fix sending out multiple experiment cookies
Only classify people into an experiment when we are rewriting html.
Fixes https://github.com/pagespeed/ngx_pagespeed/issues/586
2014-01-24 22:09:31 +01:00
Jeff Kaufman c20affe323 Merge pull request #605 from pagespeed/oschaaf-date-header
Date header: use current date when we don't get one handed over
2014-01-24 08:47:00 -08:00
Otto van der Schaaf 7a9e6de802 Date header: use current date when we don't get one handed over
When the content generator does not supply us with a date header,
we need to create one ourselves and set it to the current date.

Fixes:
https://github.com/pagespeed/ngx_pagespeed/issues/604 (duplicate)
https://github.com/pagespeed/ngx_pagespeed/issues/577
2014-01-24 16:49:37 +01:00
Huibao Lin 96cf9a22f7 Update to 1.7.30.3 release 2014-01-16 18:37:36 -05:00
Jeff Kaufman ab83a70a35 Merge pull request #599 from eezis/docfix
Added a missing 'cd ~' command to the README
2014-01-16 13:30:44 -08:00
huibaolin 6db4d02a91 Merge pull request #600 from pagespeed/huibao-prepare-release-1.7.30.3-beta
release: prepare 1.7.30.3
2014-01-16 12:12:53 -08:00
Huibao Lin 1354cee4ed release: prepare 1.7.30.3 2014-01-16 15:06:49 -05:00
Ernest Ezis 658b2cf7a9 Added the missing 'cd ~' command to the '3. Download and build nginx:' section 2014-01-16 12:45:14 -07:00
Jeff Kaufman 092bbf2862 Merge pull request #597 from pagespeed/jefftk-update-trunk-tracking
trunk-tracking: update from r3696 to r3714
2014-01-16 07:18:31 -08:00
tcpper 6ccb815df3 fix bug in NgxFetch#content_length_ 2014-01-16 21:06:12 +08:00
Jeff Kaufman f04c533df0 trunk-tracking: update from r3696 to r3714
https://code.google.com/p/modpagespeed/source/detail?r=3697
 * system test improvements

https://code.google.com/p/modpagespeed/source/detail?r=3699
 * moved some config from location block to server block
 * system test improvements

https://code.google.com/p/modpagespeed/source/detail?r=3707
 * tests for OptimizeForBandwidth
   * had to switch tests from directory blocks to server+location blocks

https://code.google.com/p/modpagespeed/source/detail?r=3708
 * update to a test that had never been ported

* ngx_pagespeed.cc:
  * change in signature of FindIgnoreCase

https://code.google.com/p/modpagespeed/source/detail?r=3689
 * Was apparently skipped with #591.
2014-01-15 13:18:47 -05:00
Jeff Kaufman 8468e4849a Merge branch 'master' into trunk-tracking 2014-01-08 10:51:42 -05:00
Jeff Kaufman df5736609d native-fetcher: add support for FetchProxy
The native fetcher previously ignored FetchProxy settings; now it doesn't.

Squash-merge of tcpper's #590.
2014-01-08 10:51:24 -05:00
Jeff Kaufman 72ddb34a1c readme: release 1.7.30.2 2014-01-06 16:54:56 -05:00
Jeff Kaufman 7fbb2c61ee readme: release 1.7.30.2 2014-01-06 16:51:41 -05:00
Jeff Kaufman ae2d4bac7f 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.
2014-01-06 16:46:48 -05:00
Jeff Kaufman af772c2fe8 Merge pull request #592 from pagespeed/jefftk-better-configure-error
config: point people to obj/autoconf.err when psol isn't detected
2014-01-03 03:33:47 -08:00
Jeff Kaufman a4bd9b9c13 config: point people to obj/autoconf.err when psol isn't detected by ./configure 2014-01-02 23:09:42 -05:00
Jeff Kaufman f87d0f7ae2 Merge pull request #591 from pagespeed/jud-trunk-tracking
Updates to trunk tracking branch.
2014-01-02 13:43:11 -08:00
Jud Porter 501742cb56 trunk-tracking: update from r3677 to r3696.
Add inline unauthorized resources test and fix rendered image dimensions test.
2014-01-02 16:42:10 -05:00
Jeff Kaufman a669be99b1 Merge branch 'master' into trunk-tracking 2014-01-02 16:25:23 -05:00
Jeff Kaufman 328d3afc9b Merge pull request #583 from pagespeed/jefftk-support-purge
native-fetcher: support non-GET request methods like PURGE
2013-12-20 07:11:55 -08:00
Jeff Kaufman 2681c24ee0 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.
2013-12-19 12:46:53 -05:00
Jeff Kaufman f86f47fda4 native-fetcher: support non-GET request methods like PURGE 2013-12-19 11:38:46 -05:00
Jeff Kaufman 179c81afa3 test: don't run downstream caching test with native fetcher 2013-12-19 11:03:53 -05:00
Jeff Kaufman 8d7eb20c89 Merge pull request #575 from pagespeed/dec9-trunk-tracking-updates
Trunk tracking updates to sync to PSOl r3677.
2013-12-13 07:14:30 -08:00
Anupama Dutta 1fe6c54b94 Trunk tracking updates to sync to PSOl r3677.
Includes minor additions to test only.

Trunk tracking updates to sync to PSOl r3677.

Trunk tracking update to sync to PSOL r3677

Includes minor additions to test only.
2013-12-12 22:27:27 -05:00
Jeff Kaufman 1667879202 Merge pull request #571 from morlovich/morlovich-trunk-tracking-20131125
Trunk tracking update for up to r3646
2013-12-02 07:45:08 -08:00
Maks Orlovich 0076e45677 Port over ModPagespeed r3635: RespectXForwardedProto is vhost-scope 2013-11-27 12:59:47 -05:00
Jeff Kaufman 1f3560ea21 backport header-only fix
Was: trunk-tracking: update to r3632 from 1.7.30.1
2013-11-26 16:39:52 -05:00
Jeff Kaufman 54352bff72 trunk-tracking: update to r3632 from 1.7.30.1 2013-11-26 16:37:30 -05:00
Maks Orlovich 329985659c Fix flakey test
It doesn't make sense to fetch_until the uncombined URL and then
grep for combined one: you might just get entirely unoptimized
output and fail the test. Instead wait for the combining to happen,
and make sure it combined the right # of things.
2013-11-25 16:32:31 -05:00
Maks Orlovich db870f7023 Update to pagespeed_automatic.ca more symbols + symbol renaming
This make it possible to build w/o disabling SSL, makes us need
less extra .a + .cc files, but does mean that APR can't be used
directly (since it got renamed), so just use PosixTimer where it was
used.
2013-11-25 15:36:30 -05:00
Jeff Kaufman ed14455412 valgrind: unflake cache purging test
Fixes #569.
2013-11-25 14:38:24 -05:00
Jeff Kaufman be4d263d10 valgrind: suppressions file might not be in current directory 2013-11-25 10:23:25 -05:00
Jeff Kaufman 0bafd6b7e0 Merge pull request #565 from pagespeed/oschaaf-valgrind
Valgrind: Add an automated test
2013-11-25 07:03:33 -08:00
Otto van der Schaaf 9bbe912bd7 Valgrind: Add an automated test
This makes nginx run in the background under valgrind,
with both a master and a child process.
Valgrind errors will be redirected to `valgrind.log`.
When `USE_VALGRIND` is set, all system tests will be run under valgrind,
and at the end a new test is appended which ensures no valgrind errors
where encountered.

It is also worth noting that:
- There is a new file, `valgrind.sup`, which contains a few suppressions.
- Some tests behave flakey under valgrind. For now these are appended
  to the expected failures (when under valgrind only).
- 'Possibly lost' errors are all suppressed to get the amount of false
  positives manageable.
2013-11-21 21:26:15 +01:00
Jeff Kaufman b78eb8a939 Merge pull request #567 from pagespeed/oschaaf-304-timeout
system-tests: Test keepalive behaviour after a 304 response
2013-11-21 11:05:18 -08:00
Otto van der Schaaf e082a01912 system-tests: Test keepalive behaviour after a 304 response 2013-11-20 23:15:14 +01:00
Jeff Kaufman fa5815e1e8 Merge pull request #560 from pagespeed/jefftk-fix-messages
messages: unbreak /ngx_pagespeed_messages
2013-11-12 11:51:57 -08:00
Jeff Kaufman f12af2f03b messages: unbreak /ngx_pagespeed_messages
The shared circular buffer wasn't hooked up fully, which meant loading
/ngx_pagespeed_messages didn't work.  This fixes that and adds a test.

I also noticed while adding this that the 'Handling of large files' test
wasn't set up properly, so I converted that to use start_test.

Fixing that exposed another bug where the 'Handling of large files' test
was actually failing but being marked as an expected failure by being
grouped in with the test above.  Adding `pagespeed MaxHtmlParseBytes 5000`
to the appropriate location made it test what it was supposed to be testing
again, and the underlying feature wasn't broken.
2013-11-12 13:11:12 -05:00
Jeff Kaufman e22fae46bc readme: use release 2013-11-08 11:41:53 -05:00
Jeff Kaufman 53a599fbd4 readme: recommend tmpfs for file cache 2013-11-08 11:36:16 -05:00
Jeff Kaufman 70c47c13a4 Merge pull request #557 from pagespeed/jefftk-fix-header-only
headers: don't special case header-only requests
2013-11-08 08:32:57 -08:00
Jeff Kaufman 8021751d69 headers: don't special case header-only requests
Fixes #537.
2013-11-08 11:21:52 -05:00
Jeff Kaufman 6b29b5220d Merge pull request #555 from pagespeed/jefftk-prepare-release-1.7.30.1-beta
trunk-tracking: update to 1.7.30.1 from r3581
2013-11-08 08:19:27 -08:00
Jeff Kaufman 07286005a6 trunk-tracking: update to 1.7.30.1 from r3581
Changes:
 * r3585: With downstream caching, don't touch `Cache-Control` headers.
   * No longer require `Modify Caching Headers off`.
   * Change from `modify_caching_headers` as a boolean to a three valued enum
     `PreserveCachingHeaders`.
 * r3596: Make tests less flaky.
   * Changes WGET_DUMP to write to WGET_DIR instead of OUTDIR.
 * r3597: Remove now-redundant system tests.
   * Some system tests were moved into `automatic/system_test.sh` which means we
     can remove our forks.
 * r3598: Enable the shared memory metadata cache by default.
   * The code change just worked and needed no changes, but it also added
     substantial tests, which needed some porting.
 * Deflake the `scrape stats` test by moving it before config reloading.
2013-11-07 17:47:37 -05:00
Jeff Kaufman 721c49dc71 release: version 1.6.29.7 -> 1.7.30.1 2013-11-07 17:47:07 -05:00
Jeff Kaufman 658a30d836 Merge branch 'master' into trunk-tracking 2013-11-07 17:46:30 -05:00
Jeff Kaufman 94688bd1e5 Merge pull request #556 from pagespeed/jefftk-increase-timeout
system-test: increase timeout for keepalive tests from 1s to 2s
2013-11-07 14:46:11 -08:00
Jeff Kaufman 26aaf221c7 system-test: increase timeout for keepalive tests from 1s to 2s
The keepalive tests were occasionally bumping up against
the 1s timeout we had set for curl, but a 1s 99.9% tail
latency is a little agressive.  Drop it to 2s to make the
tests less flaky.

What we really need is a proper load testing setup, so
the keepalive test isn't doing double-duty.
2013-11-07 17:36:56 -05:00
Jeff Kaufman 530bf3c05e prepare-psol: properly include generated console files 2013-11-06 16:38:10 -05:00
Jeff Kaufman dfedc6b025 merge commit 2013-11-06 15:20:40 -05:00
Jeff Kaufman 4e3fe6f35f readme: suggest restricting the global statistics handler 2013-10-29 17:06:50 -04:00
Jeff Kaufman af6706a4c9 Merge pull request #550 from pagespeed/jefftk-update-trunk-tracking
trunk-tracking: update to r3581 (from r3537)
2013-10-29 06:46:47 -07:00
Jeff Kaufman b6c3001df2 trunk-tracking: update to r3581 (from r3537) 2013-10-28 16:52:56 -04:00
Jeff Kaufman b8ff84ed9b Factor out handling for errors, stats, and logs. Add nosniff protection. 2013-10-28 10:15:03 -04:00
Jeff Kaufman b83bb636f0 Factor out handling for errors, stats, and logs. Add nosniff protection. 2013-10-28 10:09:24 -04:00
Jeff Kaufman 7d6b6c4b4c versions: 1.6.29.5 -> 1.6.29.7 2013-10-28 09:59:45 -04:00
Jeff Kaufman 2629865c59 versions: 1.6.29.5 -> 1.6.29.7 2013-10-28 09:58:19 -04:00
Jeff Kaufman fd546f270b readme: 1.4.3 is stable 2013-10-23 16:25:36 -04:00
Jeff Kaufman 641fb971d1 merge commit 2013-10-23 11:07:05 -04:00
Jeff Kaufman e40cde221c Merge pull request #547 from pagespeed/jefftk-fix-dir-permissions
paths: don't require existence
2013-10-23 07:26:54 -07:00
Jeff Kaufman f956ef92e9 paths: don't require existence
Create paths for FileCachePath and LogDir if they don't exist yet and give
them proper permissions.
2013-10-22 16:47:49 -04:00
Jeff Kaufman 687e0a7028 readme: reword the canonicalize_javascript_libraries note 2013-10-21 13:26:26 -04:00
Jeff Kaufman 7c15cd83f4 canonicalize libraries: script to convert from Apache format to Nginx
Merge of Vid's #533 with some fixes.
2013-10-21 13:21:28 -04:00
Jeff Kaufman 8f6ac0660e Merge pull request #543 from pagespeed/oschaaf-shared-mem-trunk-tracking
trunk-tracking: update to build with mps r3537
2013-10-18 08:37:45 -07:00
Otto van der Schaaf 422d5afa6b trunk-tracking: update to build with mps r3537 2013-10-18 11:46:09 +02:00
Jeff Kaufman f653094040 Merge pull request #536 from pagespeed/jefftk-vlogs
logging: restore call to log_message_handler::Install()
2013-10-07 07:47:36 -07:00
Jeff Kaufman 8430a6c40e logging: remove unused constant 2013-10-04 17:52:35 -04:00
Jeff Kaufman d4fa76463d logging: restore call to log_message_handler::Install()
I missed this when moving shared components to SystemRewriteDriverFactory;
this call used to be in NgxRewriteDriverFactory::RootInit.  Without it we only
log VLOG(0), not VLOG(1) and VLOG(2) the way Apache does.

Fixes #518.
2013-10-04 17:50:19 -04:00
Jeff Kaufman 1e5769df11 Merge pull request #535 from pagespeed/jefftk-close-connection-v3
logging: fix use-after-free
2013-10-04 10:42:47 -07:00
Jeff Kaufman f1a800d37f logging: fix use-after-free
The pagespeed_connection needs a log to write to, but unfortunately
r->connection->log isn't guaranteed to still be around for the whole
lifetime of the pagespeed_connection.  Use the log from the server
context instead.

Fixes issue #522.
2013-10-04 13:21:42 -04:00
Jeff Kaufman ee4958e7dd Merge pull request #530 from pagespeed/oschaaf-process-context
Use net_instaweb::ProcessContext
2013-10-01 14:19:55 -07:00
Jeff Kaufman dbead4a62e Merge pull request #529 from pagespeed/jefftk-ipro-headers
ipro: support calling ps_in_place_body_filter multiple times
2013-09-25 08:21:42 -07:00
Jeff Kaufman 2b2d19e78d ipro: support calling ps_in_place_body_filter multiple times
Fixes #520
2013-09-25 11:21:33 -04:00
Jeff Kaufman 9ed9fecc0f ipro: fix typo: 2013-09-25 10:07:50 -04:00
Jeff Kaufman 06e64dec7a Merge pull request #531 from pagespeed/jefftk-update-trunk-tracking
trunk-tracking: update to r3508
2013-09-25 07:03:39 -07:00
Jeff Kaufman 420b58c346 trunk-tracking: update to r3508
No major changes that we need to be compatible with.  r3508 tweaks
InPlaceResourceRecorder::DoneAndSetHeaders so that we can now make sure to
release it: the recorder is allocated in ps_in_place_check_header_filter and
released in ps_in_place_body_filter, but if there's an error in between it will
be leaked.  We know ps_release_request_context will get run regardless because
it's set as a cleanup handler, so clean up the recorder there.

Fixes #527
2013-09-24 17:19:06 -04:00
Jeff Kaufman 36554ce92f merging: accidentally restored obselete NgxThreadSystem 2013-09-24 17:09:37 -04:00
Otto van der Schaaf c5265b47cf Use net_instaweb::ProcessContext
This fixes a few valgrind errors on shutdown, plus a potential
issue when url_util.cc would lazily initialize in a thread-unsafe
manner. Also adds --leak-check=full to the suggested valgrind
command for the system tests.
2013-09-24 23:09:14 +02:00
Jeff Kaufman c29ac1e6a3 merge commit 2013-09-24 16:16:16 -04:00
Jeff Kaufman 6e86835599 Merge pull request #528 from pagespeed/jud-gcc48
Fix GCC 4.8 build errors
2013-09-24 13:11:42 -07:00
Jud Porter f70eb5df40 Add -Wno-unused-local-typedefs and -Wno-error to CFLAGS to fix build issues on GCC 4.8. 2013-09-24 15:59:56 -04:00
Jeff Kaufman 4650aa4a3f Merge pull request #508 from pagespeed/jefftk-backport-reload-fix
reloading: backport reloading fix
2013-09-24 07:21:14 -07:00
Jeff Kaufman 34e3101edd reloading: backport reloading fix
Issue #364 was fixed upstream in r3492.  Backport the fix to master.

"We only need to shut down the caches in child processes because they are not
started in the master process.  This wasn't a problem before, but shutting down
the caches can start a thread which isn't safe to do in the master process of a
forking server like Nginx."

Also backport the change from r3497 where we use a DCHECK for
may_start_threads_.  It's bad to start threads in the root process, but it's not
worth crashing a production server over.
2013-09-13 10:11:51 -04:00
Jeff Kaufman fdbdf11bab Merge pull request #506 from pagespeed/jefftk-update-trunk-tracking
trunk-tracking: update from 3485 to 3497
2013-09-13 07:02:31 -07:00
Jeff Kaufman db238e7705 trunk-tracking: update from 3485 to 3497
* Remove NgxThreadSystem because there's now a SystemThreadSystem that
  has everything we need.
* fixes https://github.com/pagespeed/ngx_pagespeed/issues/364
2013-09-12 17:33:14 -04:00
Jeff Kaufman a196cfe071 Merge branch 'master' into trunk-tracking 2013-09-12 11:27:40 -04:00
Jeff Kaufman 442d319aef Merge pull request #505 from pagespeed/jefftk-update-trunk-tracking
trunk-tracking: update to r3485
2013-09-12 08:27:00 -07:00
Jeff Kaufman a48c243e3e config: fix typo in FLAG_MARCH 2013-09-11 09:51:12 -04:00
Jeff Kaufman 5c17cb671c trunk-tracking: update to r3485
* Adds IPRO tests that we should have copied from apache_system_test.sh back
  when we first added IPRO.
  * The "IPRO-optimized resources should have fixed size, not chunked" test
    fails.  The problem is as it says: IPRO optimized resources are being sent
    out with `Transfer-Encoding: Chunked` instead of `Content-Length: ...`.  How
    do we fix this?
* install/system_test.sh moved to net/instaweb/automatic/system_test.sh
* minor method signature changes
* url.is_valid() is gone, replaced by .IsWebValid()
* I pushed Otto's #464 upstream, and now we need to make some IPRO changes.
* beacons have nonces now, so we need to update tests.
2013-09-10 16:57:44 -04:00
Jeff Kaufman 94d004e72c Merge pull request #504 from yaoweibin/march_i686
fixed the dynamic link problem with tengine in i686 box.
2013-09-10 08:16:31 -07:00
Weibin Yao 21a9705b78 fixed the dynamic link problem with tengine in i686 box.
The compiler needs to know that __sync_add_and_fetch_4 is ok,
and this requires an instruction that didn't exist on i586 or i386.
2013-09-10 22:59:37 +08:00
Jeff Kaufman 137182792e Merge pull request #499 from pagespeed/jefftk-simplify-handlers
handlers: collect redundant handler information
2013-08-30 06:23:16 -07:00
Jeff Kaufman 3dbb845603 handlers: collect redundant handler information
Create ps_simple_handler to combine haandling for static content, statistics,
console, and messages.
2013-08-29 16:04:22 -04:00
Jeff Kaufman ac7a6bce2c Merge pull request #498 from pagespeed/jefftk-code-cleanup
code cleanup
2013-08-29 09:51:04 -07:00
Jeff Kaufman 9baf3d01d3 code cleanup
Get rid of net_instaweb:: everywhere.  By eliminating the ngx_psol namespace we
can stop prefixing everything in ngx_pagespeed.cc with net_instaweb::

Fix other minor style issues.

Remove unnecessary declarations.

Rename ps_create_request_context to ps_route_request and CreateRequestContext to
RequestRouting because it no longer creates the request context.
2013-08-29 09:53:05 -04:00
Jeff Kaufman 1db13030fa trunk-tracking: update from r3403 to r3457
Statistics reporting is now handled in system/ but we need to call in.
2013-08-29 09:03:11 -04:00
Jeff Kaufman be2fb57d85 Merge pull request #495 from pagespeed/jefftk-cleanup-property-cache-lookup
property-cache: use ProxyFetchFactory::InitiatePropertyCacheLookup
2013-08-28 08:29:28 -07:00
Jeff Kaufman 3a99b9adff property-cache: use ProxyFetchFactory::InitiatePropertyCacheLookup 2013-08-28 09:37:47 -04:00
Jeff Kaufman 8cb48034f0 Merge pull request #494 from pagespeed/jefftk-update-trunk-tracking
trunk-tracking: update to r3448 from r3403
2013-08-28 06:34:49 -07:00
Jeff Kaufman 49c96c9202 trunk-tracking: update to r3448 from r3403
As of r3447 ServerContext::ChildInit is now in system/, which means we can
delete a lot of code.

DangerFetchFromUnknownHosts and FetchWithGzip are now handled by RewriteOptions.

ServerContext now needs a hostname and port, but we don't have one so we
hackishly provide a different unique id.
2013-08-27 14:10:09 -04:00
Jeff Kaufman ad2ea9498b Merge branch 'master' into trunk-tracking 2013-08-27 13:50:47 -04:00
Jeff Kaufman 3a085e114d Merge pull request #480 from pagespeed/jefftk-update-trunk-tracking
Adjust for fetchers and options that moved from apache/ to system/ in r3390
2013-08-27 07:41:24 -07:00
Jeff Kaufman 3fbb740101 Merge pull request #490 from pagespeed/new-trunk-tracking-rotation
Removing redundant X-Cache header handling.
2013-08-21 09:49:44 -07:00
Anupama Dutta fa99ac39b4 Removing redundant X-Cache header handling.
X-Cache handling is not needed because the pagespeed server never gets to see
a request with X-Cache header added by its downstream cache. X-Cache headers
are only to be added in responses served out of the downstream cache for debugging
purposes only. This piece of deleted code was also conflicting with X-Cache
headers present on upstream caches (wrt pagespeed) and hence not optimizing responses
that happened to carry this header.

(More details are present in https://github.com/pagespeed/ngx_pagespeed/issues/488)
2013-08-21 10:57:48 -04:00
Jeff Kaufman d0de777452 Merge pull request #484 from pagespeed/jefftk-base-fetch-request-headers
headers: simplify header setting
2013-08-09 15:56:46 -07:00
Jeff Kaufman eb9979f048 headers: simplify header setting
* Remove PopulateRequestHeaders() and PopulateResponseHeaders().
* Set stop copying request headers to the base fetch twice.
  * This fixes a dcheck failure in the debug build.
2013-08-09 14:10:18 -04:00
Jeff Kaufman c57c16c499 trunk-tracking: update to r3402
Adjust for fetchers and options that moved from apache/ to system/ in r3390.

Use AllocateFetcher() hook from r3402 to put the native fetcher into the fetcher
map maintained by the SystemRewriteDriverFactory.
2013-08-08 10:49:34 -04:00
Jeff Kaufman 70284c987e Merge pull request #477 from pagespeed/jefftk-style
style: indentation and other minor style fixes
2013-08-06 07:46:14 -07:00
Jeff Kaufman 64f2ab6591 style: indentation and other minor style fixes 2013-08-06 10:07:49 -04:00
Jeff Kaufman c739bf29c4 Merge branch 'master' into trunk-tracking 2013-08-05 17:30:36 -04:00
Jeff Kaufman bb1093e8b2 Merge pull request #469 from pagespeed/jefftk-update-trunk-tracking
trunk-tracking: take advantage of new functionality in system/
2013-08-05 14:24:25 -07:00
Jeff Kaufman 51eaeddfba trunk-tracking: update apache_system_test for minor changes in r3369 and r3374 2013-08-05 17:23:23 -04:00
Jeff Kaufman 122c234570 trunk-tracking: adjust for big changes from r3366
SystemRewriteDriverFactory was expanded by r3366 to do a lot of what
NgxRewriteDriverFactory used to have to do.  Take advantage of this and
simplifiy our code.
2013-08-05 11:22:58 -04:00
Jeff Kaufman ddf844b680 Merge pull request #473 from pagespeed/oschaaf-response-header-options
response-header-options: consider the response headers for options
2013-08-05 08:06:34 -07:00
Otto van der Schaaf a245f40bcf Merge pull request #472 from pagespeed/oschaaf-native-fetcher-timeouts
native-fetcher: timeouts
2013-08-05 07:57:44 -07:00
Otto van der Schaaf cafb06c011 native-fetcher: timeouts
After more testing, it turns out that the timer that is initially set
in Init() remains active throughout the whole lifetime of the fetch.

This reverts the previous change, which isn't correct, and replaces
all TODO's concerning timers with a comment about that we don't need
them.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/466
2013-08-05 16:57:02 +02:00
Otto van der Schaaf cbfbb5b6d6 response-header-options: consider the response headers for options
Take the response headers into account when determining the options
for the request. Also adds tests for this.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/356
2013-08-05 16:42:49 +02:00
Jeff Kaufman 606a75a068 Merge pull request #474 from pagespeed/oschaaf-max-buffer-size
max-buffer-size: use ngx_pagesize
2013-08-05 04:44:38 -07:00
Jeff Kaufman 0c26aafc2f Merge pull request #471 from pagespeed/oschaaf-pointer-declaration-style
pointer-declaration-style: fix style issues
2013-08-05 04:32:47 -07:00
Otto van der Schaaf 8bd4ed2ec2 max-buffer-size: use ngx_pagesize
Other modules seem to use ngx_pagesize as the default buffer size:
http://lxr.evanmiller.org/http/source/http/modules/ngx_http_gunzip_filter_module.c#L661
2013-08-05 10:33:47 +02:00
Otto van der Schaaf 9c5fb3107e pointer-declaration-style: fix style issues 2013-08-04 15:25:26 +02:00
Otto van der Schaaf 1c86ab66be Merge pull request #465 from pagespeed/oschaaf-native-fetcher-crash
native-fetcher: fix a crasher, and set a timeout
2013-08-03 00:06:13 -07:00
Otto van der Schaaf f05e3cf281 native-fetcher: fix a crasher, and set a timeout
Handle the case where ngx_event_connect_peer didn't return NGX_OK.
Also replace a TODO for adding a timer with actually adding the
timer.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/463
2013-08-01 15:39:02 +02:00
Jeff Kaufman 177b70b995 Merge pull request #460 from pagespeed/oschaaf-test-accidental-quotes
system-test: remove a few stray quotes
2013-07-30 13:53:29 -07:00
Otto van der Schaaf 3b2b28559a system-test: remove a few stray quotes
This fixes nginx's complaints about receiving invalid headers after
running the system tests.
2013-07-30 22:43:39 +02:00
Jeff Kaufman 7e89db8fa1 trunk-tracking: in_place_resource_recorder changes 2013-07-30 15:38:42 -04:00
Jeff Kaufman 9b3ab25cea Merge branch 'master' into trunk-tracking 2013-07-30 15:27:53 -04:00
Otto van der Schaaf 54ef25214c Merge pull request #457 from pagespeed/oschaaf-modify-headers
header-handling: ModifyCachingheaders & Content-Encoding
2013-07-30 12:19:46 -07:00
Otto van der Schaaf b9db498199 header-handling: ModifyCachingHeaders & Content-Encoding
- Change header handling for ModifyCachingHeaders
- Don't copy over response headers which have their hash set to 0
- Don't invent a date header
2013-07-30 21:14:49 +02:00
Jeff Kaufman 6503ebfb1a merge commit 2013-07-30 14:30:55 -04:00
Jeff Kaufman baf35dc906 Merge pull request #458 from pagespeed/jud-trunk-tracking
Trunk tracking updates
2013-07-26 12:14:24 -07:00
Jud Porter f4466918f3 System test changes to align with latest mod_pagespeed trunk. 2013-07-26 14:54:02 -04:00
Jeff Kaufman 3b6caa38aa release: merging readme changes for 1.6.29.5 2013-07-25 14:31:45 -04:00
Jeff Kaufman b1127c2a01 release: 1.6.29.5 2013-07-25 13:56:28 -04:00
Jeff Kaufman ad6429d26f ipro: support in-place resource optimization
Squash-merge of chaizhenhua's work over many pull requests, especially #450.

The copy of in_place_resource_recorder.cc is temporary and can be removed after
the next PSOL release.
2013-07-24 10:45:39 -04:00
Jeff Kaufman 59cdafaf70 Merge pull request #454 from pagespeed/oschaaf-force-caching
force-caching: fix configuration handling
2013-07-24 07:15:40 -07:00
Otto van der Schaaf 34ebc2d179 force-caching: fix configuration handling
Make pagespeed ForceCaching [on|off] work
2013-07-23 13:12:24 +02:00
Otto van der Schaaf 49c9de63cd Merge pull request #448 from pagespeed/oschaaf-log-vhost-specific
logging: respect error_log in nginx.conf server blocks
2013-07-23 01:52:34 -07:00
Otto van der Schaaf 502a604a26 logging: respect error_log in nginx.conf server blocks
This makes messages written via the NgxMessageHandler from the
NgxServerContext be written with the nginx error_log configuration
specified at the server{} level, if specified.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/447
2013-07-23 10:51:47 +02:00
Jeff Kaufman fca58f2d6f Merge pull request #444 from morlovich/morlovich-trunk-tracking-20130719
trunk-tracking: merge with MPS trunk as of 2003-07-19
2013-07-22 07:13:31 -07:00
Jeff Kaufman b2bbdcc0df Merge pull request #443 from patschi/patch-2
readme: recommend nginx 1.4.2 stable
2013-07-22 07:05:20 -07:00
Otto van der Schaaf bdb5de5a2f Merge pull request #446 from pagespeed/oschaaf-missing-beacon-urls
system-tests: fix missing beacon urls
2013-07-22 04:56:18 -07:00
Otto van der Schaaf 960d0940bb system-tests: fix missing beacon url parameters in tests
Fix 2 tests on the beacon by adding the missing url parameter
2013-07-21 14:20:16 +02:00
Otto van der Schaaf e7a91c2f0a Merge pull request #445 from pagespeed/oschaaf-fix-keepalive-test-gzip
keepalive-test: fix gzip accept encoding
2013-07-20 03:11:06 -07:00
Otto van der Schaaf e583afdb49 keepalive-test: fix gzip accept encoding
We would send "Accept-Encoding:gzip" in the request headers. NGINX
would mark that as an invalid header, as it misses a space after ':'
2013-07-20 09:06:38 +02:00
Maks Orlovich 53138d7b34 Merge with MPS trunk as of 2003-07-19
This has 2 families of changes:
- Port to changes in PropertyCache API
- Update to a MapProxyDomain test.
2013-07-19 14:28:46 -04:00
Patschi e45acf4613 nginx 1.4.2 stable released
Changelog: http://nginx.org/en/CHANGES-1.4
2013-07-19 14:45:21 +02:00
Otto van der Schaaf 47e3364332 Merge pull request #439 from pagespeed/oschaaf-shutdown-fix
shutdown: fix segfault when shutting down a worker process
2013-07-18 14:21:12 -07:00
Otto van der Schaaf 49760f03a0 shutdown: fix a crash when shutting down a worker process
Remove the deferred cleanup, as in ngx_pagespeed the fetcher
is owned by the RewriteDriverFactory.

Fixes the backtrace pointing to
net_instaweb::RewriteDriverFactory::Deleter
at https://github.com/pagespeed/ngx_pagespeed/issues/367
2013-07-18 23:20:03 +02:00
Jud Porter 2f5afcddd1 Merge pull request #440 from pagespeed/anupama-updates-to-trunk-tracking
Updating trunk-tracking to be in sync with r3298.
2013-07-15 11:05:43 -07:00
Anupama Dutta 67beee1444 Updating trunk-tracking to be in sync with r3298.
Fixes to allow ngx_pagespeed trunk-tracking branch to compile and work with r3298 mod_pagespeed revision:
- Config fix to include path for critical_keys.pb.h.
- Make changes needed due to RewriteOptions refactoring done in https://code.google.com/p/modpagespeed/source/detail?r=3226
2013-07-15 13:20:14 -04:00
Jeff Kaufman cd80e92df1 Merge pull request #435 from pagespeed/oschaaf-refactor-static-handler
static-handler: refactor to use write_handler_response
2013-07-12 13:33:30 -07:00
Otto van der Schaaf e303c92041 Merge pull request #437 from pagespeed/oschaaf-downstream-cache-fix-test
downstream-cache-test: don't hard code the port to 8051
2013-07-12 09:26:47 -07:00
Otto van der Schaaf ccd36dd658 downstream-cache-test: don't hard code the port to 8051 2013-07-12 18:21:55 +02:00
Otto van der Schaaf 3a9953e25c static-handler: refactor to use write_handler_response
This fixes sending out the weak ETag for ngx_pagespeed_static/js_defer.hash.js,
and simplifies things somewhat for this code path.
It also adds a test for it.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/434
2013-07-12 18:12:13 +02:00
Jeff Kaufman 311ea897cf Merge pull request #436 from pagespeed/jefftk-simplify-option-setting
options: refactor repeated code in option setting
2013-07-12 07:55:07 -07:00
Jeff Kaufman 4cc3e4def3 options: refactor repeated code in option setting 2013-07-12 10:44:34 -04:00
Jeff Kaufman 301a5249a8 Merge branch 'master' into trunk-tracking 2013-07-10 12:44:50 -04:00
Otto van der Schaaf 4bff89e8af Merge pull request #431 from pagespeed/oschaaf-fix-keepalive-test
keepalive-test: prevent false positives, filter a little more
2013-07-09 23:40:42 -07:00
Jeff Kaufman fa29f9ff32 merge: rate controlled fetcher 2013-07-09 10:07:13 -04:00
Jeff Kaufman aeba9eb285 Merge pull request #428 from pagespeed/jefftk-head-get
request: allow alternate request methods when rewriting html
2013-07-09 07:01:46 -07:00
Otto van der Schaaf 5d2e2d7b67 keepalive-test: prevent false positives, filter a little more
From the comments at https://github.com/pagespeed/ngx_pagespeed/pull/425,
on Chai's machine curl's output seems slightly different when it
reports it is trying to connect.
2013-07-09 15:36:57 +02:00
Jeff Kaufman e61c4f722f test: expect fewer arguments in beacon 2013-07-08 16:51:01 -04:00
Jeff Kaufman 505d3be9b9 Merge pull request #427 from pagespeed/oschaaf-rate-limiting
fetch-rate-limiting: add rate limiting for background fetches
2013-07-08 08:16:55 -07:00
Jeff Kaufman bec52734f9 request: allow alternate request methods when rewriting html 2013-07-08 11:10:25 -04:00
Otto van der Schaaf 73f7531ed5 fetch-rate-limiting: add rate limiting for background fetches
Limits the number of simultaneous background fetches performed.
Requires statistics to be turned on.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/426
2013-07-08 16:38:02 +02:00
Jeff Kaufman 96fbca62e0 Merge pull request #423 from pagespeed/oschaaf-double-forward-declaration
double-forward-declaration: remove a duplicate forward declaration
2013-07-07 08:05:12 -07:00
Otto van der Schaaf 36aed99813 double-forward-declaration: remove a duplicate forward declaration 2013-07-06 23:03:04 +02:00
Jeff Kaufman e1cd69e672 release: 1.6.29.2 -> 1.6.29.3 2013-07-04 09:48:52 -04:00
Jeff Kaufman 41f75282d8 release: 1.5.27.3 -> 1.6.29.2 in documentation 2013-07-02 11:20:48 -04:00
Jeff Kaufman aa6ef1d6f2 Merge pull request #420 from pagespeed/jefftk-trunk-tracking-nocache
headers: pass through no-store; don't duplicate cache-control
2013-07-02 08:16:33 -07:00
Jeff Kaufman 40fc16b1ea headers: pass through no-store; don't duplicate cache-control 2013-07-02 10:49:12 -04:00
Jeff Kaufman db882d350c Merge pull request #419 from pagespeed/jefftk-update-trunk-tracking
trunk-tracking: update to 1.6.29.2
2013-07-01 11:30:57 -07:00
Jeff Kaufman 3edd4f851f trunk-tracking: update to 1.6.29.2
* ConsoleHandler now takes a RewriteOptions
* Console needs ports to override the statistics handler path.  Before the
  console just assumed statistics were available at /mod_pagespeed_statistics.
* The "nostore" test fails.  I've marked this as an expected failure and will
  fix it in a followup.
* downstream_cache_purges stat was renamed to downstream_cache_purge_attempts
* Proxying tests with gstatic no longer use 1.gif but are switched to
  pss-architecture.png.
* DownstreamCacheLifetimeMs option was removed.
2013-07-01 14:21:09 -04:00
Jeff Kaufman cd2be9aa9c Merge pull request #417 from pagespeed/anupama-updates-to-trunk-tracking
caching: Conf updates wrt "location" option.
2013-06-25 13:01:00 -07:00
Anupama Dutta 52e1c189fa caching: Conf updates wrt "location" option.
Uses DownstreamCachePurgeLocationPrefix to avoid loopback through pagespeed server for purge requests.
2013-06-25 15:53:13 -04:00
Jeff Kaufman 0231f021ad Merge pull request #415 from pagespeed/jefftk-console
console: support /pagespeed_console
2013-06-25 08:45:43 -07:00
Jeff Kaufman 25e9fba38c console: support /pagespeed_console
sligocki is adding a feature to pagespeed where it will parse your statistics
for you and determine if there are any problems.  This CL wires up the
ConsoleHandler and also includes a few required files in the build process.

It doesn't work yet, because as of svn r3193 the console has a hardcoded json
request to '/mod_pagespeed_statistics' and in nginx we use '/ngx_...' .
I've tested this by changing all uses here to use the "mod_..." version and that
worked, but I've undone those changes.
2013-06-25 11:45:16 -04:00
Jeff Kaufman 0fc61adb30 Merge pull request #414 from pagespeed/jefftk-update-trunk-tracking
trunk-tracking: update to r3193
2013-06-24 12:04:54 -07:00
Jeff Kaufman 84ff166375 trunk-tracking: update to r3193
* statistics_logging_file_prefix is gone, replaced with log_dir
* propagate a units fix from apache_system_test
* test nonces for critical css beaconing

Previous trunk-tracking was at 3162.  Diff of apache_system_test.sh:
  https://code.google.com/p/modpagespeed/source/diff?path=/trunk/src/install/apache_system_test.sh&format=side&r=3193&old_path=/trunk/src/install/apache_system_test.sh&old=3162
2013-06-24 15:03:54 -04:00
Jeff Kaufman 04ab9a06e7 Merge pull request #412 from morlovich/morlovich-trunk-tracking-20030614
Update to match trunk as of 2003-06-17 (r3162)
2013-06-17 13:18:48 -07:00
Maks Orlovich f8454d500a Update to match trunk as of 2003-06-17.
This matches two changes:
- Anupama made the caching tests use downstream_caching.html
(Thanks to her for help in updating this)
- Jan updated some configuration defaults, which made some images
compress more.
2013-06-17 14:42:36 -04:00
Jeff Kaufman 1904494276 Merge pull request #409 from pagespeed/anupama-update-trunk-tracking-html-caching
caching: Sample proxy_cache_key construction.
2013-06-11 10:59:43 -07:00
Anupama Dutta a421f6c501 caching: Sample proxy_cache_key construction.
Adding a nginx conf snippet for constructing a proxy_cache_key based on the UserAgent and expected optimizations for that UserAgent class, bypassing the cache for all other cases. Sample config for downstream-cache proxy_cache_key construction now takes care of 2 classes of UserAgents (expected to get most of the traffic for a site) and also bypasses cache for all other desktop UAs, all mobile UAs and all tablet UAs.

(Fixing the startup phase of the nginx server to put out the original error message in case of failure.)
2013-06-11 13:33:07 -04:00
Jeff Kaufman 3359910784 Merge pull request #407 from pagespeed/anupama-updates-to-trunk-tracking
Updating trunk-tracking against PSOL r3130.
2013-06-10 14:03:11 -07:00
Anupama Dutta 1f7bab2faf Updating trunk-tracking against PSOL r3130.
Small fix for compilation error caused due to removal of all synchronous fetchers in r3128.
2013-06-10 14:18:54 -04:00
Jud Porter 4d85b56e1e Merge pull request #405 from pagespeed/jud-trunk-tracking
Fix build errors with trunk
2013-06-10 07:43:20 -07:00
Jud Porter 261e46a6d1 Merge branch 'jud-trunk-tracking' of https://github.com/pagespeed/ngx_pagespeed into jud-trunk-tracking 2013-06-10 10:32:22 -04:00
Jud Porter 556cf508f1 Revert removing system/ cc files, as that causes linker errors. 2013-06-10 10:30:20 -04:00
Jud Porter a668eafc38 Remove unnecessary cc sources from config. 2013-06-10 10:30:20 -04:00
Jud Porter a0fdf4b940 Fix add_instrumentation test. 2013-06-10 10:30:20 -04:00
Jud Porter 6f845f9fa5 Use SystemRewriteDriverFactory::InitStats instead of RewriteDriverFactory::InitStats 2013-06-10 10:30:20 -04:00
Jud Porter 7e9c6b2dbc Add CFLAGS to fix OpenSSL linker error. 2013-06-10 10:30:20 -04:00
Jud Porter d9c19b98b7 Fix paths for files moved from apache/ to system/ 2013-06-10 10:30:20 -04:00
Jud Porter 841eca0e99 Revert removing system/ cc files, as that causes linker errors. 2013-06-07 18:51:23 -04:00
Jud Porter 1a819e74c3 Remove unnecessary cc sources from config. 2013-06-07 18:19:26 -04:00
Jud Porter fcf56710d3 Fix add_instrumentation test. 2013-06-07 17:25:56 -04:00
Jud Porter c8094915b7 Use SystemRewriteDriverFactory::InitStats instead of RewriteDriverFactory::InitStats 2013-06-07 16:41:20 -04:00
Jud Porter 6d0e256f1b Add CFLAGS to fix OpenSSL linker error. 2013-06-07 16:39:44 -04:00
Jeff Kaufman 8e76e14f4e caching: support for proxy_cache
Add support for proxy_cache integration with pagespeed with:

a) Handling cache-hit-header to bypass content handling by pagespeed.
b) pagespeed_test_conf.template with the proxy_cache configuration blocks.
c) System tests for checking hit and miss headers and purge requests.
d) Checking for proxy_cache_purge module during start-up for tests.

Squash-merge of Anupama's #404
2013-06-07 11:44:47 -04:00
Jud Porter b5bb232044 Fix paths for files moved from apache/ to system/ 2013-06-07 10:52:03 -04:00
Jeff Kaufman 2503f406b6 Merge branch 'master' into trunk-tracking 2013-06-06 14:18:08 -04:00
Jeff Kaufman b04132e341 Merge pull request #396 from pagespeed/anupama-update-trunk-tracking
Getting it working with mod_pagespeed (r3061).
2013-06-03 09:43:37 -07:00
Anupama Dutta 9b7e2571bd Getting it working with mod_pagespeed (r3061).
Updating trunk-tracking to compile and work with mod_pagespeed svn revision 3061 with 2 small modifications to serf_url_async_fetcher.cc to disable SERF_HTTPS_FETCHING.

Please note that anyone building mod_pagespeed from source will need to
a) edit serf_url_async_fetcher.h to change the line "#define SERF_HTTPS_FETCHING 1" to have 0.
b) edit serf_url_async_fetcher.cc to move the definition of "apr_status_t status = APR_SUCCESS;" on line 265 to be inside the "#if SERF_HTTPS_FETCHING" block (in order to avoid a compilation error for psol/mod_pagespeed).

Highlights of this change:

1) Propagating renaming changes related to
  a) Furious -> Experiment
  b) ModPagespeed -> PageSpeed.
2) UrlPollableAsyncFetcher going away.
3) RewriteOptions now requiring a ThreadSystem parameter for construction.
4) Removing client_property_cache references and usages (since this was removed from mod_pagespeed).
5) Propagating beacon construction changes (where POST requests can now carry the url query param in the request).
6) General fixes for API/test breakages in statistics_logger, fallback property page cache,
2013-05-30 15:42:38 -04:00
Jeff Kaufman 888265b36a Merge pull request #393 from pagespeed/jefftk-loop-headers
ngx-list-iterator: Make it easier to iterate over headers.  Fixes #359.
2013-05-29 11:28:31 -07:00
Jeff Kaufman 6da81d760d ngx-list-iterator: Make it easier to iterate over headers. Fixes #359. 2013-05-29 13:43:35 -04:00
Otto van der Schaaf 08cc94bdb3 Merge pull request #391 from pagespeed/oschaaf-keepalive-test-more
keepalive-tests: add more keepalive tests
2013-05-29 08:14:55 -07:00
Otto van der Schaaf e010be17a9 keepalive-tests: add more keepalive tests
- beacon get requests
- beacon post requests
- requests on /ngx_pagespeed_static
- requests on .pagespeed. resources
2013-05-29 17:09:04 +02:00
Jeff Kaufman a898bad02d Merge pull request #389 from pagespeed/oschaaf-keepalive-test
keepalive-test: Test that we handle keep-alive requests OK
2013-05-28 10:42:13 -07:00
Otto van der Schaaf 8e1cbbf967 keepalive-test: Test that we handle keep-alive requests OK
Add a keepalive test which is repeated 100 times, with us both
behind the gzip filter and directly behind nginx's output filter.
The reason for that is that modules running after us can mask
our errors, this at least tests the most used ones.

This CL adds a failure to the expected failures, as currently,
this tests gives suspicious messages in nginx's error.log:
"client prematurely closed connection while sending response to client"

We should probably also test other code paths, like .pagespeed.
resources and the beacon with post requests as well. If this approach
is generally ok, I can proceed to add those as well.
2013-05-28 19:36:08 +02:00
Jeff Kaufman 4a4ba6592b readme: google pagespeed docs now include ngx_pagespeed 2013-05-28 11:08:03 -04:00
Jeff Kaufman b3624743e3 Merge pull request #385 from pagespeed/jefftk-quieter-startup
options: remove option parsing messages
2013-05-20 10:03:25 -07:00
Jeff Kaufman e8a284d2e7 options: remove option parsing messages 2013-05-18 14:50:31 -04:00
94 changed files with 12590 additions and 5197 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
test/tmp
psol/
psol-*.tar.gz
*.*.*.*.tar.gz
nginx
+18
View File
@@ -0,0 +1,18 @@
[submodule "testing-dependencies/mod_pagespeed"]
path = testing-dependencies/mod_pagespeed
url = https://github.com/apache/incubator-pagespeed-mod.git
[submodule "testing-dependencies/ngx_cache_purge"]
path = testing-dependencies/ngx_cache_purge
url = https://github.com/FRiCKLE/ngx_cache_purge.git
[submodule "testing-dependencies/nginx"]
path = testing-dependencies/nginx
url = https://github.com/nginx/nginx.git
[submodule "testing-dependencies/set-misc-nginx-module"]
path = testing-dependencies/set-misc-nginx-module
url = https://github.com/openresty/set-misc-nginx-module
[submodule "testing-dependencies/ngx_devel_kit"]
path = testing-dependencies/ngx_devel_kit
url = https://github.com/simpl/ngx_devel_kit
[submodule "testing-dependencies/headers-more-nginx-module"]
path = testing-dependencies/headers-more-nginx-module
url = https://github.com/openresty/headers-more-nginx-module
+33
View File
@@ -0,0 +1,33 @@
language: c++
env:
global:
- MAKEFLAGS=-j3
# By default travis loads submodules serially, but we can load them in parallel
# if we install an updated git and use --jobs. Some timing numbers:
# serial: 257s
# jobs=4: 182s (29s to install new git, 153s to run the downloads)
# jobs=8: 179s (29s to install new git, 150s to run the downloads)
# We can't use --depth=1, though, because github doesn't have
# allowReachableSHA1InWant set.
#
# TODO(jefftk): once we're running on a server with git 2.8 or later we can have
# --jobs without installing a new git.
git:
submodules: false
before_install:
- sudo add-apt-repository --yes ppa:git-core/ppa
- sudo apt-get update
- sudo apt-get install git
- git submodule update --init --recursive --jobs=8
install:
scripts/build_ngx_pagespeed.sh --devel --assume-yes
script:
test/run_tests.sh $PWD/testing-dependencies/mod_pagespeed/ \
$PWD/nginx/sbin/nginx
dist: trusty
sudo: required
compiler:
- gcc
notifications:
email:
- pagespeed-ci@googlegroups.com
+17
View File
@@ -0,0 +1,17 @@
Apache ngx_pagespeed
Copyright 2018 The Apache Software Foundation
This product includes software developed at
- The Apache Software Foundation (http://www.apache.org/).
- Google Inc.
Codebase originally donated by Google Inc:
Copyright (C) 2010-2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
+4
View File
@@ -0,0 +1,4 @@
In a release this file would contain the URL to download the pre-compiled PSOL
binary, but on development branches (like this one) you have to build PSOL from
source yourself. See:
https://github.com/apache/incubator-pagespeed-ngx/wiki/Building-PSOL-From-Source
+9 -104
View File
@@ -1,4 +1,6 @@
![ngx_pagespeed](https://lh6.googleusercontent.com/-qufedJIJq7Y/UXEvVYxyYvI/AAAAAAAADo8/JHDFQhs91_c/s401/04_ngx_pagespeed.png)
![ngx_pagespeed](https://user-images.githubusercontent.com/6751650/73116078-338a9180-3f0f-11ea-8fdf-8c99cb4bec7f.png)
[![Build Status](https://travis-ci.org/apache/incubator-pagespeed-ngx.svg?branch=master)](https://travis-ci.org/apache/incubator-pagespeed-ngx)
ngx_pagespeed speeds up your site and reduces page load time by automatically
applying web performance best practices to pages and associated assets (CSS,
@@ -19,112 +21,15 @@ optimizations, see our <a href="http://ngxpagespeed.com">demonstration site</a>.
## How to build
Because nginx does not support dynamic loading of modules, you need to compile
nginx from source to add ngx_pagespeed. Alternatively, if you're using Tengine you can [install ngx_pagespeed without
recompiling Tengine](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-ngx_pagespeed-with-Tengine).
1. Install dependencies:
```bash
# These are for RedHat, CentOS, and Fedora.
$ sudo yum install gcc-c++ pcre-dev pcre-devel zlib-devel make
# These are for Debian. Ubuntu will be similar.
$ sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev
```
2. Download ngx_pagespeed:
```bash
$ cd ~
$ wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.5.27.3-beta.zip
$ unzip release-1.5.27.3-beta.zip # or unzip release-1.5.27.3-beta
$ cd ngx_pagespeed-release-1.5.27.3-beta/
$ wget https://dl.google.com/dl/page-speed/psol/1.5.27.3.tar.gz
$ tar -xzvf 1.5.27.3.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.1.tar.gz
$ tar -xvzf nginx-1.4.1.tar.gz
$ cd nginx-1.4.1/
$ ./configure --add-module=$HOME/ngx_pagespeed-release-1.5.27.3-beta
$ make
$ sudo make install
```
If this doesn't work see the [build
troubleshooting](https://github.com/pagespeed/ngx_pagespeed/wiki/Build-Troubleshooting) page.
This will use a binary PageSpeed Optimization Library, but it's also possible to
[build PSOL from
source](https://github.com/pagespeed/ngx_pagespeed/wiki/Building-PSOL-From-Source).
Note: ngx_pagespeed currently doesn't support Windows or MacOS because the
underlying PSOL library doesn't.
Follow the steps on <a
href="https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source">build
ngx_pagespeed from source</a>.
## How to use
In your `nginx.conf`, add to the main or server block:
```nginx
pagespeed on;
# needs to exist and be writable by nginx
pagespeed FileCachePath /var/ngx_pagespeed_cache;
```
In every server block where pagespeed is enabled add:
```apache
# Ensure requests for pagespeed optimized resources go to the pagespeed
# handler and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
location ~ "^/ngx_pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }
```
To confirm that the module is loaded, fetch a page and check that you see the
`X-Page-Speed` header:
```bash
$ curl -I 'http://localhost:8050/some_page/' | grep X-Page-Speed
X-Page-Speed: 1.5.27.3-...
```
Looking at the source of a few pages you should see various changes, such as
urls being replaced with new ones like `yellow.css.pagespeed.ce.lzJ8VcVi1l.css`.
When reading the [mod_pagespeed
documentation](https://developers.google.com/speed/docs/mod_pagespeed/using_mod),
keep in mind that you need to make a small adjustment to configuration
directives: replace **ModPagespeed** with **pagespeed**:
mod_pagespeed.conf:
ModPagespeedEnableFilters collapse_whitespace,add_instrumentation
ModPagespeedRunExperiment on
ModPagespeedExperimentSpec id=3;percent=50;default
ModPagespeedExperimentSpec id=4;percent=50
ngx_pagespeed.conf:
pagespeed EnableFilters collapse_whitespace,add_instrumentation;
pagespeed RunExperiment on;
pagespeed ExperimentSpec "id=3;percent=50;default";
pagespeed ExperimentSpec "id=4;percent=50";
For more configuration details, see the [differences from mod_pagespeed
configuration](https://github.com/pagespeed/ngx_pagespeed/wiki/Configuration-differences-from-mod_pagespeed)
and <a href="https://github.com/pagespeed/ngx_pagespeed/wiki/Known-Issues">known
issues</a> wiki pages.
There are extensive system tests which cover most of ngx_pagespeed's
functionality. Consider [testing your
installation](https://github.com/pagespeed/ngx_pagespeed/wiki/Testing).
Follow the steps on <a
href="https://developers.google.com/speed/pagespeed/module/configuration">PageSpeed
configuration</a>.
For feedback, questions, and to follow
the progress of the project:
+1
View File
@@ -0,0 +1 @@
This podling has been retired, please see: http://incubator.apache.org/projects/index.html#pagespeed
+291 -86
View File
@@ -15,44 +15,44 @@
# Environment Variables (Optional):
# MOD_PAGESPEED_DIR: absolute path to the mod_pagespeed/src directory
# PSOL_BINARY: absolute path to pagespeed_automatic.a
# PSOL_BUILDTYPE: Release or Debug
mod_pagespeed_dir="${MOD_PAGESPEED_DIR:-unset}"
position_aux="${POSITION_AUX:-unset}"
psol_buildtype="${PSOL_BUILDTYPE:-unset}"
if [ "$mod_pagespeed_dir" = "unset" ] ; then
mod_pagespeed_dir="$ngx_addon_dir/psol/include"
build_from_source=false
if [ ! -e "$mod_pagespeed_dir" ] ; then
echo "ngx_pagespeed: pagespeed optimization library not found:"
echo ""
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.5.27.3.tar.gz"
echo " $ tar -xzvf 1.5.27.3.tar.gz # expands to psol/"
echo ""
echo " Or see the installation instructions:"
echo " https://github.com/pagespeed/ngx_pagespeed#how-to-build"
psol_binary_url="$($ngx_addon_dir/scripts/format_binary_url.sh \
$ngx_addon_dir/PSOL_BINARY_URL)"
if [[ "$psol_binary_url" != https://* ]]; then
echo "
This is a development branch of ngx_pagespeed, which means there is no
precompiled PSOL library available to link against. Either build from a
release tag, like latest-beta, or build PSOL from source:
https://github.com/apache/incubator-pagespeed-ngx/wiki/Building-PSOL-From-Source"
exit 1
fi
echo "
You need to separately download the pagespeed library:
$ cd $ngx_addon_dir
$ wget $psol_binary_url
$ tar -xzvf $(basename $psol_binary_url) # expands to psol/
Or see the installation instructions:
https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source"
exit 1
fi
else
build_from_source=true
fi
echo "mod_pagespeed_dir=$mod_pagespeed_dir"
echo "build_from_source=$build_from_source"
ngx_feature="psol"
ngx_feature_name=""
ngx_feature_run=no
ngx_feature_incs="
#include \"net/instaweb/htmlparse/public/html_parse.h\"
#include \"net/instaweb/htmlparse/public/html_writer_filter.h\"
#include \"net/instaweb/util/public/string.h\"
#include \"net/instaweb/util/public/string_writer.h\"
#include \"net/instaweb/util/public/null_message_handler.h\"
"
os_name='unknown_os'
arch_name='unknown_arch'
uname_os=`uname`
@@ -77,44 +77,137 @@ else
exit 1
fi
if [ "$NGX_DEBUG" = "YES" ]; then
buildtype=Debug
if [ "$psol_buildtype" = "unset" ] ; then
if [ "$NGX_DEBUG" = "YES" ]; then
buildtype=Debug
# If we're using a psol tarball that doesn't contain Debug/ (which is the case
# from 1.12 onward) then this will be overriden to buildtype=Release below.
else
buildtype=Release
fi
else
buildtype=Release
buildtype=$psol_buildtype
fi
# If the compiler is gcc, we want to use g++ to link, if at all possible,
# so that -static-libstdc++ works.
# Annoyingly, the feature test doesn't even use $LINK for linking, so that
# needs an explicit -lstdc++
pagespeed_libs=
ps_maybe_gpp_base=`basename $CC| sed s/gcc/g++/`
ps_maybe_gpp="`dirname $CC`/$ps_maybe_gpp_base"
if [ -n "$NGX_GCC_VER" -a \( -x "$ps_maybe_gpp" \) ]; then
LINK=$ps_maybe_gpp
fi
pagespeed_libs="-lstdc++"
# The compiler needs to know that __sync_add_and_fetch_4 is ok,
# and this requires an instruction that didn't exist on i586 or i386.
if [ "$uname_arch" = "i686" ]; then
FLAG_MARCH='-march=i686'
fi
CFLAGS="$CFLAGS $FLAG_MARCH"
# For now, standardize on gcc-4.x ABI --- if we don't set this, people building
# with new gcc defaulting to gcc-5 C++11 ABI will have build trouble linking
# to our libpsol.a
# See https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
CFLAGS="$CFLAGS -D_GLIBCXX_USE_CXX11_ABI=0"
CC_OLD_TEST_FLAGS="$CC_TEST_FLAGS"
CC_TEST_FLAGS="$CC_TEST_FLAGS -D_GLIBCXX_USE_CXX11_ABI=0 --std=c++11"
case "$NGX_GCC_VER" in
4.8*)
# On GCC 4.8 and above, -Wall enables -Wunused-local-typedefs. This breaks
# on VerifySizesAreEqual in bit_cast in chromium/src/base/basictypes.h which
# has a typedef that is intentionally unused.
CFLAGS="$CFLAGS -Wno-unused-local-typedefs"
# On GCC 4.8 and above, we get the following compiler warning:
# chromium/src/base/memory/scoped_ptr.h:133:7: warning: declaration of class scoped_ptr<C> [enabled by default]
# Based on discussion at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54055,
# this is invalid code, but hasn't been fixed yet in chromium.
# Unfortunately, there also does not appear to be a flag for just disabling
# that warning, so we add Wno-error to override nginx's default -Werror
# option.
CFLAGS="$CFLAGS -Wno-error"
;;
esac
# workaround for a bug in nginx-1.9.11, see:
# http://hg.nginx.org/nginx/rev/ff1e625ae55b
NGX_VERSION=`grep nginx_version src/core/nginx.h | sed -e 's/^.* \(.*\)$/\1/'`
if [ "$NGX_VERSION" = "1009011" ]; then
CFLAGS="$CFLAGS -Wno-write-strings"
fi
if [ "$WNO_ERROR" = "YES" ]; then
CFLAGS="$CFLAGS -Wno-error"
fi
psol_binary="${PSOL_BINARY:-unset}"
if [ "$psol_binary" = "unset" ] ; then
if $build_from_source ; then
psol_binary="\
$mod_pagespeed_dir/pagespeed/automatic/pagespeed_automatic.a"
else
if ! [ -d "$ngx_addon_dir/psol/lib/$buildtype" ]; then
echo "
You have set --with-debug for building nginx, but precompiled Debug binaries for
PSOL, which ngx_pagespeed depends on, aren't available. If you're trying to
debug PSOL you need to build it from source. If you just want to run nginx with
debug-level logging you can use the Release binaries."
echo -n "
Use the available Release binaries?"
read -p " [Y/n] " yn
if [[ "$yn" == N* || "$yn" == n* ]]; then
echo "Cancelled."
exit 1
fi
buildtype=Release
fi
psol_library_dir="$ngx_addon_dir/psol/lib/$buildtype/$os_name/$arch_name"
psol_binary="$psol_library_dir/pagespeed_automatic.a"
fi
fi
echo "mod_pagespeed_dir=$mod_pagespeed_dir"
echo "build_from_source=$build_from_source"
ngx_feature="psol"
ngx_feature_name=""
ngx_feature_run=no
ngx_feature_incs="
#include \"pagespeed/kernel/base/string.h\"
#include \"pagespeed/kernel/base/string_writer.h\"
#include \"pagespeed/kernel/base/null_message_handler.h\"
#include \"pagespeed/kernel/html/html_parse.h\"
#include \"pagespeed/kernel/html/html_writer_filter.h\"
"
pagespeed_include="\
$mod_pagespeed_dir \
$mod_pagespeed_dir/third_party/chromium/src \
$mod_pagespeed_dir/third_party/google-sparsehash/src \
$mod_pagespeed_dir/third_party/google-sparsehash/src/src \
$mod_pagespeed_dir/third_party/google-sparsehash/gen/arch/$os_name/$arch_name/include \
$mod_pagespeed_dir/third_party/protobuf/src \
$mod_pagespeed_dir/third_party/grpc/src/include \
$mod_pagespeed_dir/third_party/protobuf/src/src \
$mod_pagespeed_dir/third_party/re2/src \
$mod_pagespeed_dir/out/$buildtype/obj/gen \
$mod_pagespeed_dir/out/$buildtype/obj/gen/protoc_out/instaweb \
$mod_pagespeed_dir/third_party/apr/src/include \
$mod_pagespeed_dir/third_party/aprutil/src/include \
$mod_pagespeed_dir/third_party/apr/gen/arch/$os_name/$arch_name/include \
$mod_pagespeed_dir/third_party/aprutil/gen/arch/$os_name/$arch_name/include"
$mod_pagespeed_dir/third_party/aprutil/gen/arch/$os_name/$arch_name/include \
$mod_pagespeed_dir/url"
ngx_feature_path="$pagespeed_include"
if $build_from_source ; then
psol_library_binaries="\
$mod_pagespeed_dir/net/instaweb/automatic/pagespeed_automatic.a \
$mod_pagespeed_dir/out/$buildtype/obj.target/third_party/serf/libserf.a \
$mod_pagespeed_dir/out/$buildtype/obj.target/third_party/aprutil/libaprutil.a \
$mod_pagespeed_dir/out/$buildtype/obj.target/third_party/apr/libapr.a"
else
psol_library_dir="$ngx_addon_dir/psol/lib/$buildtype/$os_name/$arch_name"
psol_library_binaries="\
$psol_library_dir/pagespeed_automatic.a \
$psol_library_dir/libserf.a \
$psol_library_dir/libaprutil.a \
$psol_library_dir/libapr.a"
fi
pagespeed_libs="-lstdc++ $psol_library_binaries -lrt -pthread -lm"
pagespeed_libs="$psol_binary $pagespeed_libs -lrt -pthread -lm -luuid"
ngx_feature_libs="$pagespeed_libs"
ngx_feature_test="
GoogleString output_buffer;
net_instaweb::StringWriter write_to_string(&output_buffer);
@@ -135,51 +228,163 @@ ngx_feature_test="
# Test whether we have pagespeed and can compile and link against it.
. "$ngx_addon_dir/cpp_feature"
if [ $ngx_found = yes ]; then
ps_src="$ngx_addon_dir/src"
ngx_addon_name=ngx_pagespeed
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
$ps_src/ngx_pagespeed.h \
$ps_src/ngx_fetch.h \
$ps_src/ngx_url_async_fetcher.h \
$ps_src/ngx_base_fetch.h \
$ps_src/ngx_server_context.h \
$ps_src/ngx_rewrite_options.h \
$ps_src/ngx_rewrite_driver_factory.h \
$ps_src/ngx_thread_system.h \
$ps_src/ngx_message_handler.h \
$ps_src/pthread_shared_mem.h \
$ps_src/ngx_request_context.h \
$ps_src/log_message_handler.h"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
$ps_src/ngx_pagespeed.cc \
$ps_src/ngx_rewrite_driver_factory.cc \
$ps_src/ngx_rewrite_options.cc \
$ps_src/ngx_server_context.cc \
$ps_src/ngx_fetch.cc \
$ps_src/ngx_url_async_fetcher.cc \
$ps_src/ngx_base_fetch.cc \
$ps_src/ngx_thread_system.cc \
$ps_src/ngx_message_handler.cc \
$ps_src/pthread_shared_mem.cc \
$ps_src/ngx_request_context.cc \
$ps_src/log_message_handler.cc \
$mod_pagespeed_dir/net/instaweb/apache/add_headers_fetcher.cc \
$mod_pagespeed_dir/net/instaweb/apache/loopback_route_fetcher.cc \
$mod_pagespeed_dir/net/instaweb/apache/serf_url_async_fetcher.cc"
# Make pagespeed run immediately before gzip.
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES |\
sed "s/$HTTP_GZIP_FILTER_MODULE/$HTTP_GZIP_FILTER_MODULE $ngx_addon_name/")
# Make the etag header filter run immediately after gzip.
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES |\
sed "s/$HTTP_GZIP_FILTER_MODULE/ngx_pagespeed_etag_filter $HTTP_GZIP_FILTER_MODULE/")
if [ $ngx_found = no ]; then
cat << END
$0: error: module ngx_pagespeed requires the pagespeed optimization library.
Look in $PWD/$NGX_AUTOCONF_ERR for more details.
END
exit 1
fi
ps_src="$ngx_addon_dir/src"
ngx_addon_name=ngx_pagespeed
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
$ps_src/log_message_handler.h \
$ps_src/ngx_base_fetch.h \
$ps_src/ngx_caching_headers.h \
$ps_src/ngx_event_connection.h \
$ps_src/ngx_fetch.h \
$ps_src/ngx_gzip_setter.h \
$ps_src/ngx_list_iterator.h \
$ps_src/ngx_message_handler.h \
$ps_src/ngx_pagespeed.h \
$ps_src/ngx_rewrite_driver_factory.h \
$ps_src/ngx_rewrite_options.h \
$ps_src/ngx_server_context.h \
$ps_src/ngx_url_async_fetcher.h \
$psol_binary"
NPS_SRCS=" \
$ps_src/log_message_handler.cc \
$ps_src/ngx_base_fetch.cc \
$ps_src/ngx_caching_headers.cc \
$ps_src/ngx_event_connection.cc \
$ps_src/ngx_fetch.cc \
$ps_src/ngx_gzip_setter.cc \
$ps_src/ngx_list_iterator.cc \
$ps_src/ngx_message_handler.cc \
$ps_src/ngx_pagespeed.cc \
$ps_src/ngx_rewrite_driver_factory.cc \
$ps_src/ngx_rewrite_options.cc \
$ps_src/ngx_server_context.cc \
$ps_src/ngx_url_async_fetcher.cc"
# Save our sources in a separate var since we may need it in config.make
PS_NGX_SRCS="$NGX_ADDON_SRCS \
$NPS_SRCS"
# Make pagespeed run immediately before gzip and Brotli.
if echo $HTTP_FILTER_MODULES | grep ngx_http_brotli_filter_module >/dev/null; then
next=ngx_http_brotli_filter_module
elif [ $HTTP_GZIP = YES ]; then
next=ngx_http_gzip_filter_module
else
next=ngx_http_range_header_filter_module
fi
if [ -n "$ngx_module_link" ]; then
# nginx-1.9.11+
ngx_module_type=HTTP_FILTER
ngx_module_name="ngx_pagespeed ngx_pagespeed_etag_filter"
ngx_module_incs="$ngx_feature_path"
ngx_module_deps=
ngx_module_srcs="$NPS_SRCS"
ngx_module_libs="$ngx_feature_libs"
ngx_module_order="ngx_http_range_header_filter_module\
ngx_pagespeed_etag_filter\
ngx_http_gzip_filter_module \
ngx_http_brotli_filter_module \
ngx_pagespeed \
ngx_http_postpone_filter_module \
ngx_http_ssi_filter_module \
ngx_http_charset_filter_module \
ngx_http_xslt_filter_module \
ngx_http_image_filter_module \
ngx_http_sub_filter_module \
ngx_http_addition_filter_module \
ngx_http_gunzip_filter_module \
ngx_http_userid_filter_module \
ngx_http_headers_filter_module"
. auto/module
if [ $ngx_module_link != DYNAMIC ]; then
# ngx_module_order doesn't work with static modules,
# so we must re-order filters here.
if [ "$position_aux" = "true" ] ; then
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES $ngx_addon_name"
else
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES \
| sed "s/ngx_pagespeed//" \
| sed "s/$next/$next ngx_pagespeed/")
fi
# Make the etag header filter run immediately before range header filter.
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES \
| sed "s/ngx_pagespeed_etag_filter//" \
| sed "s/ngx_http_range_header_filter_module/ngx_http_range_header_filter_module ngx_pagespeed_etag_filter/")
else
if [ "$position_aux" = "true" ] ; then
ngx_module_type=HTTP_AUX_FILTER
ngx_module_order=""
fi
fi
else
CORE_LIBS="$CORE_LIBS $pagespeed_libs"
CORE_INCS="$CORE_INCS $pagespeed_include"
else
NGX_ADDON_SRCS="$PS_NGX_SRCS"
if [ "$position_aux" = "true" ] ; then
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES $ngx_addon_name"
else
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES | sed "s/$next/$next $ngx_addon_name/")
fi
# Make the etag header filter run immediately before range header filter.
HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES |\
sed "s/ngx_http_range_header_filter_module/ngx_http_range_header_filter_module ngx_pagespeed_etag_filter/")
fi
echo "List of modules (in reverse order of applicability): "$HTTP_FILTER_MODULES
# Test whether the compiler is compatible
ngx_feature="psol-compiler-compat"
ngx_feature_name=""
ngx_feature_run=no
ngx_feature_incs=""
ngx_feature_path=""
ngx_feature_libs="-lstdc++"
ngx_feature_test="
#if defined(__clang__) && defined(__GLIBCXX__)
// See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning
// for a list of various values of __GLIBCXX__. Note that they're not monotonic
// with respect to version numbers.
#if __GLIBCXX__ == 20120322 || __GLIBCXX__ == 20120614
#error \"clang is using libstdc++ 4.7.0 or 4.7.1, which can cause binary incompatibility.\"
#endif
#endif
#if !defined(__clang__) && defined(__GNUC__)
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
#error \"GCC < 4.8 no longer supported. Please use gcc >= 4.8 or clang >= 3.3\"
#endif
#endif
#if defined(__clang__)
#if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 3)
#error \"Please use gcc >= 4.8 or clang >= 3.3\"
#endif
#endif
"
. "$ngx_addon_dir/cpp_feature"
if [ $ngx_found = no ]; then
cat << END
$0: error: module ngx_pagespeed requires the pagespeed optimization library
$0: error: module ngx_pagespeed requires gcc >= 4.8 or clang >= 3.3.
See https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source for some recommendations.
Look in $PWD/$NGX_AUTOCONF_ERR for more details.
END
exit 1
fi
have=NGX_PAGESPEED . auto/have
CC_TEST_FLAGS="$CC_OLD_TEST_FLAGS"
+25
View File
@@ -0,0 +1,25 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Since nginx build system doesn't normally do C++, there is no CXXFLAGS for us
# to touch, and compilers are understandably unhappy with --std=c++11 on C
# files. Hence, we hack the makefile to add it for just our sources.
for ps_src_file in $PS_NGX_SRCS; do
ps_obj_file="$NGX_OBJS/addon/src/`basename $ps_src_file .cc`.o"
echo "$ps_obj_file : CFLAGS += --std=c++11" >> $NGX_MAKEFILE
done
+187
View File
@@ -0,0 +1,187 @@
# Supported tags and respective `Dockerfile` links
- [`1.13.35.2`, `stable`, `1.13.35`, `1.13`, `1.13.35.2-alpine3.8`, `1.13.35-alpine3.8`, `1.13-alpine3.8`, `stable-alpine3.8`, `1.13.35.2-alpine3.8-ngx1.14`, `1.13.35-alpine3.8-ngx1.14`, `1.13-alpine3.8-ngx1.14`, `stable-alpine3.8-ngx1.14`, `latest` (*alpine-3.8/nginx-stable/Dockerfile*)](https://github.com/apache/incubator-pagespeed-ngx/blob/master/docker/alpine-3.8/nginx-stable/Dockerfile)
- [`1.13.35.2-edge`, `stable-edge`, `edge`, `1.13.35-edge`, `1.13-edge`, `1.13.35.2-edge-ngx1.14`, `1.13.35-edge-ngx1.14`, `1.13-edge-ngx1.14`, `stable-edge-ngx1.14` (*alpine-edge/nginx-stable/Dockerfile*)](https://github.com/apache/incubator-pagespeed-ngx/blob/master/docker/alpine-edge/nginx-stable/Dockerfile)
- [`1.13.35.2-alpine3.8-ngx1.15`, `ngx1.15`, `1.13.35-alpine3.8-ngx1.15`, `1.13-alpine3.8-ngx1.15`, `stable-alpine3.8-ngx1.15` (*alpine-3.8/nginx-mainline/Dockerfile*)](https://github.com/apache/incubator-pagespeed-ngx/blob//master/docker/alpine-3.8/nginx-mainline/Dockerfile)
- [`1.13.35.2-edge-ngx1.15`, `1.13.35-edge-ngx1.15`, `1.13-edge-ngx1.15`, `stable-edge-ngx1.15` (*alpine-edge/nginx-mainline/Dockerfile*)](https://github.com/apache/incubator-pagespeed-ngx/blob/master/docker/alpine-edge/nginx-mainline/Dockerfile)
# Quick reference
- **Where to get help**:
[Read the wiki](https://github.com/apache/incubator-pagespeed-mod/wiki), [Ask a question on the mailing list](https://groups.google.com/group/ngx-pagespeed-discuss)
- **Docker image repository**:
[Dockerhub](https://hub.docker.com/r/pagespeed/nginx-pagespeed)
- **Git Dockerfile repository**:
[Github](https://github.com/apache/incubator-pagespeed-ngx/tree/master/docker)
- **Where to file issues**:
[https://github.com/We-Amp/ngx-pagespeed-alpine/issues](https://github.com/apache/incubator-pagespeed-ngx/issues)
- **Docker images maintained by**:
[Nico Berlee](mailto:nico.berlee@on2it.net)
- **Supported Docker versions**:
[the latest release](https://github.com/docker/docker-ce/releases/latest) (down to 1.12 on a best-effort basis)
# What is pagespeed?
The PageSpeed Modules, [mod_pagespeed](https://github.com/apache/incubator-pagespeed-mod) and [ngx_pagespeed](https://github.com/apache/incubator-pagespeed-ngx), are open-source webserver modules that [optimize your site automatically](https://www.modpagespeed.com/doc/filters).
ngx_pagespeed speeds up your site and reduces page load time by automatically
applying web performance best practices to pages and associated assets (CSS,
JavaScript, images) without requiring you to modify your existing content or
workflow. Features include:
- Image optimization: stripping meta-data, dynamic resizing, recompression
- CSS & JavaScript minification, concatenation, inlining, and outlining
- Small resource inlining
- Deferring image and JavaScript loading
- HTML rewriting
- Cache lifetime extension
- and [more](https://developers.google.com/speed/docs/mod_pagespeed/config_filters)
To see ngx_pagespeed in action, with example pages for each of the
optimizations, see our [demonstration site](http://ngxpagespeed.com).
![logo](https://camo.githubusercontent.com/4138679c6cf85adb18c4cf820189c898f7dbf5cb/68747470733a2f2f6c68362e676f6f676c6575736572636f6e74656e742e636f6d2f2d71756665644a494a7137592f55584576565978795976492f4141414141414141446f382f4a48444651687339315f632f733430312f30345f6e67785f7061676573706565642e706e67)
# What is nginx?
Nginx (pronounced "engine-x") is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and a web server (origin server). The nginx project started with a strong focus on high concurrency, high performance and low memory usage.
> [wikipedia.org/wiki/Nginx](https://en.wikipedia.org/wiki/Nginx)
# What is nginx-pagespeed?
The nginx-pagespeed brings all the goods of nginx and pagespeed together in one single small alpine docker image. Nginx-pagespeed aims to be 100% compatible with the plain [nginx](https://hub.docker.com/_/nginx/) images. Meaning, nginx-pagespeed can be a safe drop-in replacement for any container running `nginx:alpine`.
Nginx-pagespeed makes it easy to start optimizing your website by reducing page load time, without requiring you to modify existing content.
# How to use this image
## Hosting some simple static content
```console
$ docker run --name pagespeed-nginx -v /some/content:/usr/share/nginx/html:ro -d pagespeed/nginx-pagespeed
```
Alternatively, a simple `Dockerfile` can be used to generate a new image that includes the necessary content (which is a much cleaner solution than the bind mount above):
```dockerfile
FROM pagespeed/nginx-pagespeed
COPY static-html-directory /usr/share/nginx/html
```
Place this file in the same directory as your directory of content ("static-html-directory"), run `docker build -t some-content-ngxpagespeed .`, then start your container:
```console
$ docker run --name my-nginx-pagespeed -d some-content-ngxpagespeed
```
## Exposing external port
```console
$ docker run --name my-nginx-pagespeed -d -p 8080:80 some-content-ngxpagespeed
```
Then you can hit `http://localhost:8080` or `http://host-ip:8080` in your browser.
## Complex configuration
```console
$ docker run --name my-custom-nginx-pagespeed -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d pagespeed/nginx-pagespeed
```
For information on the syntax of the nginx configuration files, see [the official documentation](http://nginx.org/en/docs/) (specifically the [Beginner's Guide](http://nginx.org/en/docs/beginners_guide.html#conf_structure)). For pagespeed specific nginx config syntax, see [Beginner's guide](https://www.modpagespeed.com/doc/configuration) or a complete overview of [all pagespeed filters](https://www.ngxpagespeed.com/).
For a quick start on pagespeed specific configuration see []
If you wish to adapt the default configuration, use something like the following to copy it from a running nginx-pagespeed container:
```console
$ docker run --name tmp-ngxpagespeed-container -d pagespeed/nginx-pagespeed
$ docker cp tmp-ngxpagespeed-container:/etc/nginx/nginx.conf /host/path/nginx.conf
$ docker rm -f tmp-ngxpagespeed-container
```
This can also be accomplished more cleanly using a simple `Dockerfile` (in `/host/path/`):
```dockerfile
FROM pagespeed/nginx-pagespeed
COPY nginx.conf /etc/nginx/nginx.conf
```
If you add a custom `CMD` in the Dockerfile, be sure to include `-g daemon off;` in the `CMD` in order for nginx to stay in the foreground, so that Docker can track the process properly (otherwise your container will stop immediately after starting)!
Then build the image with `docker build -t custom-ngxpagespeed .` and run it as follows:
```console
$ docker run --name my-custom-ngxpagespeed-container -d custom-ngxpagespeed
```
### Using environment variables in nginx configuration
Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But `envsubst` may be used as a workaround if you need to generate your nginx configuration dynamically before nginx starts.
Here is an example using docker-compose.yml:
```yaml
web:
image: pagespeed/nginx-pagespeed
volumes:
- ./mysite.template:/etc/nginx/conf.d/mysite.template
ports:
- "8080:80"
environment:
- NGINX_HOST=foobar.com
- NGINX_PORT=80
command: /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
```
The `mysite.template` file may then contain variable references like this:
`listen ${NGINX_PORT};
`
# Image Variants
The `pagespeed/nginx-pagespeed` images come in many flavors, each designed for a specific use case.
## `pagespeed/nginx-pagespeed:<version>`
This is the defacto image. If you are unsure about what your needs are, you probably want to use this one. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of.
## `nginx:edge`
This image has the most up-to-date system packages available in the [Alpine Linux project](http://alpinelinux.org). This means the latest LibreSSL and musl-libc, with the downside of having less tested system packages.
## Using the Dockerfile
### Use docker build command to build an image from dockerfile:
docker build -t <image_tag> <dockerfile_path> .
$ docker build -t ngxpagespeed-alpine38-ngxstable stable/3.8/nginx-stable
Refer [this](https://docs.docker.com/engine/reference/commandline/build/) for additional options.
### Run this container as an independent service:
$ docker run -d -p 80:80 <image_tag>
Refer [this](https://docs.docker.com/engine/reference/run/) for additional options.
## Requirements for building:
- > 3 GB of free diskspace
- 2GB of memory
- an x86_64 compatible processor
- Docker CE > 17.3.2
# Disclaimer
Apache PageSpeed is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
# License
View [PageSpeed license information](https://github.com/apache/incubator-pagespeed-ngx/blob/master/LICENSE)
View [Nginx license information](http://nginx.org/LICENSE)
As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).
Some additional license information which was able to be auto-detected might be found in [the `repo-info` repository's `nginx/` directory](https://github.com/docker-library/repo-info/tree/master/repos/nginx).
As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.
+230
View File
@@ -0,0 +1,230 @@
ARG ALPINE_VERSION=3.8
########################
# Build pagespeed psol #
########################
FROM alpine:$ALPINE_VERSION as pagespeed
# Check https://github.com/apache/incubator-pagespeed-mod/tags
ARG MOD_PAGESPEED_TAG=v1.13.35.2
RUN apk add --no-cache \
apache2-dev \
apr-dev \
apr-util-dev \
build-base \
curl \
gettext-dev \
git \
gperf \
icu-dev \
libjpeg-turbo-dev \
libpng-dev \
libressl-dev \
pcre-dev \
py-setuptools \
zlib-dev \
;
WORKDIR /usr/src
RUN git clone -b ${MOD_PAGESPEED_TAG} \
--recurse-submodules \
--depth=1 \
-c advice.detachedHead=false \
-j`nproc` \
https://github.com/apache/incubator-pagespeed-mod.git \
modpagespeed \
;
WORKDIR /usr/src/modpagespeed
COPY patches/modpagespeed/*.patch ./
RUN for i in *.patch; do printf "\r\nApplying patch ${i%%.*}\r\n"; patch -p1 < $i || exit 1; done
WORKDIR /usr/src/modpagespeed/tools/gyp
RUN ./setup.py install
WORKDIR /usr/src/modpagespeed
RUN build/gyp_chromium --depth=. \
-D use_system_libs=1 \
&& \
cd /usr/src/modpagespeed/pagespeed/automatic && \
make psol BUILDTYPE=Release \
CFLAGS+="-I/usr/include/apr-1" \
CXXFLAGS+="-I/usr/include/apr-1 -DUCHAR_TYPE=uint16_t" \
-j`nproc` \
;
RUN mkdir -p /usr/src/ngxpagespeed/psol/lib/Release/linux/x64 && \
mkdir -p /usr/src/ngxpagespeed/psol/include/out/Release && \
cp -R out/Release/obj /usr/src/ngxpagespeed/psol/include/out/Release/ && \
cp -R pagespeed/automatic/pagespeed_automatic.a /usr/src/ngxpagespeed/psol/lib/Release/linux/x64/ && \
cp -R net \
pagespeed \
testing \
third_party \
url \
/usr/src/ngxpagespeed/psol/include/ \
;
##########################################
# Build Nginx with support for PageSpeed #
##########################################
FROM alpine:$ALPINE_VERSION AS nginx
# Check https://github.com/apache/incubator-pagespeed-ngx/tags
ARG NGX_PAGESPEED_TAG=v1.13.35.2-stable
# Check http://nginx.org/en/download.html for the latest version.
ARG NGINX_VERSION=1.15.6
ARG NGINX_PGPKEY=520A9993A1C052F8
ARG NGINX_BUILD_CONFIG="\
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-compat \
--with-file-aio \
--with-http_v2_module \
"
RUN apk add --no-cache \
apr-dev \
apr-util-dev \
build-base \
ca-certificates \
gd-dev \
geoip-dev \
git \
gnupg \
icu-dev \
libjpeg-turbo-dev \
libpng-dev \
libxslt-dev \
linux-headers \
libressl-dev \
pcre-dev \
tar \
zlib-dev \
;
WORKDIR /usr/src
RUN git clone -b ${NGX_PAGESPEED_TAG} \
--recurse-submodules \
--shallow-submodules \
--depth=1 \
-c advice.detachedHead=false \
-j`nproc` \
https://github.com/apache/incubator-pagespeed-ngx.git \
ngxpagespeed \
;
RUN wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz.asc && \
(gpg --keyserver ha.pool.sks-keyservers.net --keyserver-options timeout=10 --recv-keys ${NGINX_PGPKEY} || \
gpg --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options timeout=10 --recv-keys ${NGINX_PGPKEY} || \
gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --keyserver-options timeout=10 --recv-keys $NGINX_PGPKEY} ) && \
gpg --trusted-key ${NGINX_PGPKEY} --verify nginx-${NGINX_VERSION}.tar.gz.asc
COPY --from=pagespeed /usr/src/ngxpagespeed /usr/src/ngxpagespeed/
WORKDIR /usr/src/nginx
RUN tar zxf ../nginx-${NGINX_VERSION}.tar.gz --strip-components=1 -C . && \
./configure \
${NGINX_BUILD_CONFIG} \
--add-module=/usr/src/ngxpagespeed \
--with-ld-opt="-Wl,-z,relro,--start-group -lapr-1 -laprutil-1 -licudata -licuuc -lpng -lturbojpeg -ljpeg" \
&& \
make install -j`nproc`
RUN rm -rf /etc/nginx/html/ && \
mkdir /etc/nginx/conf.d/ && \
mkdir -p /usr/share/nginx/html/ && \
sed -i 's|^</body>|<p><a href="https://www.ngxpagespeed.com/"><img src="pagespeed.png" title="Nginx module for rewriting web pages to reduce latency and bandwidth" /></a></p>\n</body>|' html/index.html && \
install -m644 html/index.html /usr/share/nginx/html/ && \
install -m644 html/50x.html /usr/share/nginx/html/ && \
ln -s ../../usr/lib/nginx/modules /etc/nginx/modules && \
strip /usr/sbin/nginx* \
/usr/lib/nginx/modules/*.so \
;
COPY conf/nginx.conf /etc/nginx/nginx.conf
COPY conf/nginx.vh.default.conf /etc/nginx/conf.d/default.conf
COPY pagespeed.png /usr/share/nginx/html/
##########################################
# Combine everything with minimal layers #
##########################################
FROM alpine:$ALPINE_VERSION
LABEL maintainer="Nico Berlee <nico.berlee@on2it.net>" \
version.mod-pagespeed="1.13.35.2" \
version.nginx="1.15.6" \
version.ngx-pagespeed="1.13.35.2"
COPY --from=pagespeed /usr/bin/envsubst /usr/local/bin
COPY --from=nginx /usr/sbin/nginx /usr/sbin/nginx
COPY --from=nginx /usr/lib/nginx/modules/ /usr/lib/nginx/modules/
COPY --from=nginx /etc/nginx /etc/nginx
COPY --from=nginx /usr/share/nginx/html/ /usr/share/nginx/html/
RUN apk --no-cache upgrade && \
scanelf --needed --nobanner --format '%n#p' /usr/sbin/nginx /usr/lib/nginx/modules/*.so /usr/local/bin/envsubst \
| tr ',' '\n' \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
| xargs apk add --no-cache \
&& \
apk add --no-cache tzdata
RUN addgroup -S nginx && \
adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx && \
install -g nginx -o nginx -d /var/cache/ngx_pagespeed && \
mkdir -p /var/log/nginx && \
ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
@@ -0,0 +1,32 @@
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
@@ -0,0 +1,57 @@
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
pagespeed on;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/cache/ngx_pagespeed;
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

@@ -0,0 +1,31 @@
--- a/pagespeed/automatic/Makefile
+++ b/pagespeed/automatic/Makefile
@@ -146,8 +146,6 @@
pagespeed/libpagespeed_thread.a \
pagespeed/libpthread_system.a \
pagespeed/libutil.a \
- third_party/apr/libapr.a \
- third_party/aprutil/libaprutil.a \
third_party/base64/libbase64.a \
third_party/chromium/src/base/third_party/dynamic_annotations/libdynamic_annotations.a \
third_party/css_parser/libcss_parser.a \
@@ -163,18 +161,11 @@
third_party/grpc/libgrpc_core.a \
third_party/grpc/libgrpc_cpp.a \
third_party/hiredis/libhiredis.a \
- third_party/icu/libicudata.a \
- third_party/icu/libicuuc.a \
third_party/jsoncpp/libjsoncpp.a \
- third_party/libjpeg_turbo/libjpeg.a \
- third_party/libjpeg_turbo/src/libjpeg_turbo.a \
- third_party/libpng/libpng.a \
third_party/optipng/libopngreduc.a \
third_party/protobuf/libprotobuf_full_do_not_use.a \
third_party/re2/libre2.a \
- third_party/serf/libopenssl.a \
third_party/serf/libserf.a \
- third_party/zlib/libzlib.a \
url/liburl_lib.a
# The 'gclient' build flow uses 'xcodebuild' on Mac and 'make' on Linux.
@@ -0,0 +1,141 @@
From 7ea8d5fc141c7067c54ffa2b9fbc552c15089ca6 Mon Sep 17 00:00:00 2001
From: ashishk-1 <ashish.k@gdbtech.in>
Date: Thu, 18 Jan 2018 22:14:05 +0530
Subject: [PATCH] Upgrading libpng library to version 1.6 (#1724)
---
net/instaweb/rewriter/image.cc | 8 ++++++++
pagespeed/kernel/image/gif_reader.cc | 4 ++--
pagespeed/kernel/image/image_converter.cc | 6 ++++++
pagespeed/kernel/image/png_optimizer_test.cc | 6 ++++++
third_party/libpng/libpng.gyp | 26 +++++++++++++++++++++++---
third_party/libpng/src | 2 +-
6 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/net/instaweb/rewriter/image.cc b/net/instaweb/rewriter/image.cc
index 4f631182a..bb67bba35 100644
--- a/net/instaweb/rewriter/image.cc
+++ b/net/instaweb/rewriter/image.cc
@@ -21,6 +21,14 @@
#include <algorithm>
#include <cstddef>
+extern "C" {
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
+} // extern "C"
+
#include "base/logging.h"
#include "net/instaweb/rewriter/cached_result.pb.h"
#include "net/instaweb/rewriter/public/image_data_lookup.h"
diff --git a/pagespeed/kernel/image/gif_reader.cc b/pagespeed/kernel/image/gif_reader.cc
index 7de69b3d7..bb0bc9cfc 100644
--- a/pagespeed/kernel/image/gif_reader.cc
+++ b/pagespeed/kernel/image/gif_reader.cc
@@ -411,8 +411,8 @@ bool ReadGifToPng(GifFileType* gif_file,
png_uint_32 height = png_get_image_height(paletted_png_ptr,
paletted_info_ptr);
for (png_uint_32 row = 1; row < height; ++row) {
- memcpy(paletted_info_ptr->row_pointers[row],
- paletted_info_ptr->row_pointers[0],
+ memcpy(row_pointers[row],
+ row_pointers[0],
row_size);
}
diff --git a/pagespeed/kernel/image/image_converter.cc b/pagespeed/kernel/image/image_converter.cc
index d796b5065..84b7aff74 100644
--- a/pagespeed/kernel/image/image_converter.cc
+++ b/pagespeed/kernel/image/image_converter.cc
@@ -30,6 +30,12 @@ extern "C" {
#else
#include "third_party/libpng/src/png.h"
#endif
+
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
} // extern "C"
#include "base/logging.h"
diff --git a/pagespeed/kernel/image/png_optimizer_test.cc b/pagespeed/kernel/image/png_optimizer_test.cc
index 9ad915aff..3faa526a8 100644
--- a/pagespeed/kernel/image/png_optimizer_test.cc
+++ b/pagespeed/kernel/image/png_optimizer_test.cc
@@ -36,6 +36,12 @@ extern "C" {
#else
#include "third_party/libpng/src/png.h"
#endif
+
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
}
namespace {
diff --git a/third_party/libpng/libpng.gyp b/third_party/libpng/libpng.gyp
index cfaafee00..d96a8f74c 100644
--- a/third_party/libpng/libpng.gyp
+++ b/third_party/libpng/libpng.gyp
@@ -22,14 +22,29 @@
'dependencies': [
'../zlib/zlib.gyp:zlib',
],
+ 'actions': [
+ {
+ 'action_name': 'copy_libpngconf_prebuilt',
+ 'inputs' : [],
+ 'outputs': [''],
+ 'action': [
+ 'cp',
+ '-f',
+ '<(DEPTH)/third_party/libpng/src/scripts/pnglibconf.h.prebuilt',
+ '<(DEPTH)/third_party/libpng/src/pnglibconf.h',
+ ],
+ },
+ ],
'msvs_guid': 'C564F145-9172-42C3-BFCB-6014CA97DBCD',
'sources': [
+ 'src/pngpriv.h',
'src/png.c',
'src/png.h',
'src/pngconf.h',
+ 'src/pngdebug.h',
'src/pngerror.c',
- 'src/pnggccrd.c',
'src/pngget.c',
+ 'src/pnginfo.h',
'src/pngmem.c',
'src/pngpread.c',
'src/pngread.c',
@@ -37,9 +52,8 @@
'src/pngrtran.c',
'src/pngrutil.c',
'src/pngset.c',
+ 'src/pngstruct.h',
'src/pngtrans.c',
- 'src/pngusr.h',
- 'src/pngvcrd.c',
'src/pngwio.c',
'src/pngwrite.c',
'src/pngwtran.c',
@@ -54,6 +68,12 @@
# doesn't like that. This define tells libpng to not
# complain about our inclusion of setjmp.h.
'PNG_SKIP_SETJMP_CHECK',
+
+ # The PNG_FREE_ME_SUPPORTED define was dropped in libpng
+ # 1.4.0beta78, with its behavior becoming the default
+ # behavior.
+ # Hence, we define it ourselves for version >= 1.4.0
+ 'PNG_FREE_ME_SUPPORTED',
],
},
'export_dependent_settings': [
@@ -0,0 +1,11 @@
--- a/pagespeed/kernel/thread/pthread_rw_lock.cc
+++ b/pagespeed/kernel/thread/pthread_rw_lock.cc
@@ -31,7 +31,7 @@
//
// Other OS's (FreeBSD, Darwin, OpenSolaris) documentation suggests
// that they prefer writers by default.
-#ifdef linux
+#if defined(linux) && defined(__GLIBC__)
pthread_rwlockattr_setkind_np(&attr_,
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
#endif
@@ -0,0 +1,13 @@
--- a/pagespeed/automatic/rename_c_symbols.sh
+++ b/pagespeed/automatic/rename_c_symbols.sh
@@ -24,8 +24,8 @@
set -e # exit script if any command returns an error
set -u # exit the script if any variable is uninitialized
-IN=$(readlink -f $1)
-OUT=$(readlink -f $2)
+IN=$1
+OUT=$2
# Get a list of defined non-C++ symbols that are global and not weak.
# _Z is used at start of C++-mangled symbol names.
@@ -0,0 +1,64 @@
--- a/third_party/chromium/src/base/debug/stack_trace_posix.cc
+++ b/third_party/chromium/src/base/debug/stack_trace_posix.cc
@@ -5,7 +5,9 @@
#include "base/debug/stack_trace.h"
#include <errno.h>
+#if defined(HAVE_BACKTRACE)
#include <execinfo.h>
+#endif
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
@@ -64,7 +66,7 @@
// Note: code in this function is NOT async-signal safe (std::string uses
// malloc internally).
-#if defined(__GLIBCXX__)
+#if defined(__GLIBCXX__) && defined(HAVE_BACKTRACE)
std::string::size_type search_from = 0;
while (search_from < text->size()) {
@@ -145,7 +147,7 @@
handler->HandleOutput("\n");
}
-#else
+#elif defined(HAVE_BACKTRACE)
bool printed = false;
// Below part is async-signal unsafe (uses malloc), so execute it only
@@ -469,23 +471,31 @@
StackTrace::StackTrace() {
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.
-
+#if defined(HAVE_BACKTRACE)
// Though the backtrace API man page does not list any possible negative
// return values, we take no chance.
count_ = std::max(backtrace(trace_, arraysize(trace_)), 0);
+#else
+ count_ = 0;
+#endif
}
void StackTrace::Print() const {
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.
-
+#if defined(HAVE_BACKTRACE)
PrintBacktraceOutputHandler handler;
ProcessBacktrace(trace_, count_, &handler);
+#endif
}
void StackTrace::OutputToStream(std::ostream* os) const {
+#if !defined(HAVE_BACKTRACE)
+(*os) << "(stack trace not supported)\n";
+#else
StreamBacktraceOutputHandler handler(os);
ProcessBacktrace(trace_, count_, &handler);
+#endif
}
namespace internal {
+231
View File
@@ -0,0 +1,231 @@
ARG ALPINE_VERSION=3.8
########################
# Build pagespeed psol #
########################
FROM alpine:$ALPINE_VERSION as pagespeed
# Check https://github.com/apache/incubator-pagespeed-mod/tags
ARG MOD_PAGESPEED_TAG=v1.13.35.2
RUN apk add --no-cache \
apache2-dev \
apr-dev \
apr-util-dev \
build-base \
curl \
gettext-dev \
git \
gperf \
icu-dev \
libjpeg-turbo-dev \
libpng-dev \
libressl-dev \
pcre-dev \
py-setuptools \
zlib-dev \
;
WORKDIR /usr/src
RUN git clone -b ${MOD_PAGESPEED_TAG} \
--recurse-submodules \
--depth=1 \
-c advice.detachedHead=false \
-j`nproc` \
https://github.com/apache/incubator-pagespeed-mod.git \
modpagespeed \
;
WORKDIR /usr/src/modpagespeed
COPY patches/modpagespeed/*.patch ./
RUN for i in *.patch; do printf "\r\nApplying patch ${i%%.*}\r\n"; patch -p1 < $i || exit 1; done
WORKDIR /usr/src/modpagespeed/tools/gyp
RUN ./setup.py install
WORKDIR /usr/src/modpagespeed
RUN build/gyp_chromium --depth=. \
-D use_system_libs=1 \
&& \
cd /usr/src/modpagespeed/pagespeed/automatic && \
make psol BUILDTYPE=Release \
CFLAGS+="-I/usr/include/apr-1" \
CXXFLAGS+="-I/usr/include/apr-1 -DUCHAR_TYPE=uint16_t" \
-j`nproc` \
;
RUN mkdir -p /usr/src/ngxpagespeed/psol/lib/Release/linux/x64 && \
mkdir -p /usr/src/ngxpagespeed/psol/include/out/Release && \
cp -R out/Release/obj /usr/src/ngxpagespeed/psol/include/out/Release/ && \
cp -R pagespeed/automatic/pagespeed_automatic.a /usr/src/ngxpagespeed/psol/lib/Release/linux/x64/ && \
cp -R net \
pagespeed \
testing \
third_party \
url \
/usr/src/ngxpagespeed/psol/include/ \
;
##########################################
# Build Nginx with support for PageSpeed #
##########################################
FROM alpine:$ALPINE_VERSION AS nginx
# Check https://github.com/apache/incubator-pagespeed-ngx/tags
ARG NGX_PAGESPEED_TAG=v1.13.35.2-stable
# Check http://nginx.org/en/download.html for the latest version.
ARG NGINX_VERSION=1.14.1
ARG NGINX_PGPKEY=520A9993A1C052F8
ARG NGINX_BUILD_CONFIG="\
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-compat \
--with-file-aio \
--with-http_v2_module \
"
RUN apk add --no-cache \
apr-dev \
apr-util-dev \
build-base \
ca-certificates \
gd-dev \
geoip-dev \
git \
gnupg \
icu-dev \
libjpeg-turbo-dev \
libpng-dev \
libxslt-dev \
linux-headers \
libressl-dev \
pcre-dev \
tar \
zlib-dev \
;
WORKDIR /usr/src
RUN git clone -b ${NGX_PAGESPEED_TAG} \
--recurse-submodules \
--shallow-submodules \
--depth=1 \
-c advice.detachedHead=false \
-j`nproc` \
https://github.com/apache/incubator-pagespeed-ngx.git \
ngxpagespeed \
;
RUN wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz.asc && \
(gpg --keyserver ha.pool.sks-keyservers.net --keyserver-options timeout=10 --recv-keys ${NGINX_PGPKEY} || \
gpg --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options timeout=10 --recv-keys ${NGINX_PGPKEY} || \
gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --keyserver-options timeout=10 --recv-keys $NGINX_PGPKEY} ) && \
gpg --trusted-key ${NGINX_PGPKEY} --verify nginx-${NGINX_VERSION}.tar.gz.asc
COPY --from=pagespeed /usr/src/ngxpagespeed /usr/src/ngxpagespeed/
WORKDIR /usr/src/nginx
RUN tar zxf ../nginx-${NGINX_VERSION}.tar.gz --strip-components=1 -C . && \
./configure \
${NGINX_BUILD_CONFIG} \
--add-module=/usr/src/ngxpagespeed \
--with-ld-opt="-Wl,-z,relro,--start-group -lapr-1 -laprutil-1 -licudata -licuuc -lpng -lturbojpeg -ljpeg" \
&& \
make install -j`nproc`
RUN rm -rf /etc/nginx/html/ && \
mkdir /etc/nginx/conf.d/ && \
mkdir -p /usr/share/nginx/html/ && \
sed -i 's|^</body>|<p><a href="https://www.ngxpagespeed.com/"><img src="pagespeed.png" title="Nginx module for rewriting web pages to reduce latency and bandwidth" /></a></p>\n</body>|' html/index.html && \
install -m644 html/index.html /usr/share/nginx/html/ && \
install -m644 html/50x.html /usr/share/nginx/html/ && \
ln -s ../../usr/lib/nginx/modules /etc/nginx/modules && \
strip /usr/sbin/nginx* \
/usr/lib/nginx/modules/*.so \
;
COPY conf/nginx.conf /etc/nginx/nginx.conf
COPY conf/nginx.vh.default.conf /etc/nginx/conf.d/default.conf
COPY pagespeed.png /usr/share/nginx/html/
##########################################
# Combine everything with minimal layers #
##########################################
FROM alpine:$ALPINE_VERSION
LABEL maintainer="Nico Berlee <nico.berlee@on2it.net>" \
version.mod-pagespeed="1.13.35.2" \
version.nginx="1.14.1" \
version.ngx-pagespeed="1.13.35.2"
COPY --from=pagespeed /usr/bin/envsubst /usr/local/bin
COPY --from=nginx /usr/sbin/nginx /usr/sbin/nginx
COPY --from=nginx /usr/lib/nginx/modules/ /usr/lib/nginx/modules/
COPY --from=nginx /etc/nginx /etc/nginx
COPY --from=nginx /usr/share/nginx/html/ /usr/share/nginx/html/
RUN apk --no-cache upgrade && \
scanelf --needed --nobanner --format '%n#p' /usr/sbin/nginx /usr/lib/nginx/modules/*.so /usr/local/bin/envsubst \
| tr ',' '\n' \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
| xargs apk add --no-cache \
&& \
apk add --no-cache tzdata
RUN addgroup -S nginx && \
adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx && \
install -g nginx -o nginx -d /var/cache/ngx_pagespeed && \
mkdir -p /var/log/nginx && \
ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
@@ -0,0 +1,32 @@
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
@@ -0,0 +1,57 @@
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
pagespeed on;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/cache/ngx_pagespeed;
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

@@ -0,0 +1,31 @@
--- a/pagespeed/automatic/Makefile
+++ b/pagespeed/automatic/Makefile
@@ -146,8 +146,6 @@
pagespeed/libpagespeed_thread.a \
pagespeed/libpthread_system.a \
pagespeed/libutil.a \
- third_party/apr/libapr.a \
- third_party/aprutil/libaprutil.a \
third_party/base64/libbase64.a \
third_party/chromium/src/base/third_party/dynamic_annotations/libdynamic_annotations.a \
third_party/css_parser/libcss_parser.a \
@@ -163,18 +161,11 @@
third_party/grpc/libgrpc_core.a \
third_party/grpc/libgrpc_cpp.a \
third_party/hiredis/libhiredis.a \
- third_party/icu/libicudata.a \
- third_party/icu/libicuuc.a \
third_party/jsoncpp/libjsoncpp.a \
- third_party/libjpeg_turbo/libjpeg.a \
- third_party/libjpeg_turbo/src/libjpeg_turbo.a \
- third_party/libpng/libpng.a \
third_party/optipng/libopngreduc.a \
third_party/protobuf/libprotobuf_full_do_not_use.a \
third_party/re2/libre2.a \
- third_party/serf/libopenssl.a \
third_party/serf/libserf.a \
- third_party/zlib/libzlib.a \
url/liburl_lib.a
# The 'gclient' build flow uses 'xcodebuild' on Mac and 'make' on Linux.
@@ -0,0 +1,141 @@
From 7ea8d5fc141c7067c54ffa2b9fbc552c15089ca6 Mon Sep 17 00:00:00 2001
From: ashishk-1 <ashish.k@gdbtech.in>
Date: Thu, 18 Jan 2018 22:14:05 +0530
Subject: [PATCH] Upgrading libpng library to version 1.6 (#1724)
---
net/instaweb/rewriter/image.cc | 8 ++++++++
pagespeed/kernel/image/gif_reader.cc | 4 ++--
pagespeed/kernel/image/image_converter.cc | 6 ++++++
pagespeed/kernel/image/png_optimizer_test.cc | 6 ++++++
third_party/libpng/libpng.gyp | 26 +++++++++++++++++++++++---
third_party/libpng/src | 2 +-
6 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/net/instaweb/rewriter/image.cc b/net/instaweb/rewriter/image.cc
index 4f631182a..bb67bba35 100644
--- a/net/instaweb/rewriter/image.cc
+++ b/net/instaweb/rewriter/image.cc
@@ -21,6 +21,14 @@
#include <algorithm>
#include <cstddef>
+extern "C" {
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
+} // extern "C"
+
#include "base/logging.h"
#include "net/instaweb/rewriter/cached_result.pb.h"
#include "net/instaweb/rewriter/public/image_data_lookup.h"
diff --git a/pagespeed/kernel/image/gif_reader.cc b/pagespeed/kernel/image/gif_reader.cc
index 7de69b3d7..bb0bc9cfc 100644
--- a/pagespeed/kernel/image/gif_reader.cc
+++ b/pagespeed/kernel/image/gif_reader.cc
@@ -411,8 +411,8 @@ bool ReadGifToPng(GifFileType* gif_file,
png_uint_32 height = png_get_image_height(paletted_png_ptr,
paletted_info_ptr);
for (png_uint_32 row = 1; row < height; ++row) {
- memcpy(paletted_info_ptr->row_pointers[row],
- paletted_info_ptr->row_pointers[0],
+ memcpy(row_pointers[row],
+ row_pointers[0],
row_size);
}
diff --git a/pagespeed/kernel/image/image_converter.cc b/pagespeed/kernel/image/image_converter.cc
index d796b5065..84b7aff74 100644
--- a/pagespeed/kernel/image/image_converter.cc
+++ b/pagespeed/kernel/image/image_converter.cc
@@ -30,6 +30,12 @@ extern "C" {
#else
#include "third_party/libpng/src/png.h"
#endif
+
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
} // extern "C"
#include "base/logging.h"
diff --git a/pagespeed/kernel/image/png_optimizer_test.cc b/pagespeed/kernel/image/png_optimizer_test.cc
index 9ad915aff..3faa526a8 100644
--- a/pagespeed/kernel/image/png_optimizer_test.cc
+++ b/pagespeed/kernel/image/png_optimizer_test.cc
@@ -36,6 +36,12 @@ extern "C" {
#else
#include "third_party/libpng/src/png.h"
#endif
+
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
}
namespace {
diff --git a/third_party/libpng/libpng.gyp b/third_party/libpng/libpng.gyp
index cfaafee00..d96a8f74c 100644
--- a/third_party/libpng/libpng.gyp
+++ b/third_party/libpng/libpng.gyp
@@ -22,14 +22,29 @@
'dependencies': [
'../zlib/zlib.gyp:zlib',
],
+ 'actions': [
+ {
+ 'action_name': 'copy_libpngconf_prebuilt',
+ 'inputs' : [],
+ 'outputs': [''],
+ 'action': [
+ 'cp',
+ '-f',
+ '<(DEPTH)/third_party/libpng/src/scripts/pnglibconf.h.prebuilt',
+ '<(DEPTH)/third_party/libpng/src/pnglibconf.h',
+ ],
+ },
+ ],
'msvs_guid': 'C564F145-9172-42C3-BFCB-6014CA97DBCD',
'sources': [
+ 'src/pngpriv.h',
'src/png.c',
'src/png.h',
'src/pngconf.h',
+ 'src/pngdebug.h',
'src/pngerror.c',
- 'src/pnggccrd.c',
'src/pngget.c',
+ 'src/pnginfo.h',
'src/pngmem.c',
'src/pngpread.c',
'src/pngread.c',
@@ -37,9 +52,8 @@
'src/pngrtran.c',
'src/pngrutil.c',
'src/pngset.c',
+ 'src/pngstruct.h',
'src/pngtrans.c',
- 'src/pngusr.h',
- 'src/pngvcrd.c',
'src/pngwio.c',
'src/pngwrite.c',
'src/pngwtran.c',
@@ -54,6 +68,12 @@
# doesn't like that. This define tells libpng to not
# complain about our inclusion of setjmp.h.
'PNG_SKIP_SETJMP_CHECK',
+
+ # The PNG_FREE_ME_SUPPORTED define was dropped in libpng
+ # 1.4.0beta78, with its behavior becoming the default
+ # behavior.
+ # Hence, we define it ourselves for version >= 1.4.0
+ 'PNG_FREE_ME_SUPPORTED',
],
},
'export_dependent_settings': [
@@ -0,0 +1,11 @@
--- a/pagespeed/kernel/thread/pthread_rw_lock.cc
+++ b/pagespeed/kernel/thread/pthread_rw_lock.cc
@@ -31,7 +31,7 @@
//
// Other OS's (FreeBSD, Darwin, OpenSolaris) documentation suggests
// that they prefer writers by default.
-#ifdef linux
+#if defined(linux) && defined(__GLIBC__)
pthread_rwlockattr_setkind_np(&attr_,
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
#endif
@@ -0,0 +1,13 @@
--- a/pagespeed/automatic/rename_c_symbols.sh
+++ b/pagespeed/automatic/rename_c_symbols.sh
@@ -24,8 +24,8 @@
set -e # exit script if any command returns an error
set -u # exit the script if any variable is uninitialized
-IN=$(readlink -f $1)
-OUT=$(readlink -f $2)
+IN=$1
+OUT=$2
# Get a list of defined non-C++ symbols that are global and not weak.
# _Z is used at start of C++-mangled symbol names.
@@ -0,0 +1,64 @@
--- a/third_party/chromium/src/base/debug/stack_trace_posix.cc
+++ b/third_party/chromium/src/base/debug/stack_trace_posix.cc
@@ -5,7 +5,9 @@
#include "base/debug/stack_trace.h"
#include <errno.h>
+#if defined(HAVE_BACKTRACE)
#include <execinfo.h>
+#endif
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
@@ -64,7 +66,7 @@
// Note: code in this function is NOT async-signal safe (std::string uses
// malloc internally).
-#if defined(__GLIBCXX__)
+#if defined(__GLIBCXX__) && defined(HAVE_BACKTRACE)
std::string::size_type search_from = 0;
while (search_from < text->size()) {
@@ -145,7 +147,7 @@
handler->HandleOutput("\n");
}
-#else
+#elif defined(HAVE_BACKTRACE)
bool printed = false;
// Below part is async-signal unsafe (uses malloc), so execute it only
@@ -469,23 +471,31 @@
StackTrace::StackTrace() {
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.
-
+#if defined(HAVE_BACKTRACE)
// Though the backtrace API man page does not list any possible negative
// return values, we take no chance.
count_ = std::max(backtrace(trace_, arraysize(trace_)), 0);
+#else
+ count_ = 0;
+#endif
}
void StackTrace::Print() const {
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.
-
+#if defined(HAVE_BACKTRACE)
PrintBacktraceOutputHandler handler;
ProcessBacktrace(trace_, count_, &handler);
+#endif
}
void StackTrace::OutputToStream(std::ostream* os) const {
+#if !defined(HAVE_BACKTRACE)
+(*os) << "(stack trace not supported)\n";
+#else
StreamBacktraceOutputHandler handler(os);
ProcessBacktrace(trace_, count_, &handler);
+#endif
}
namespace internal {
@@ -0,0 +1,230 @@
ARG ALPINE_VERSION=edge
########################
# Build pagespeed psol #
########################
FROM alpine:$ALPINE_VERSION as pagespeed
# Check https://github.com/apache/incubator-pagespeed-mod/tags
ARG MOD_PAGESPEED_TAG=v1.13.35.2
RUN apk add --no-cache \
apache2-dev \
apr-dev \
apr-util-dev \
build-base \
curl \
gettext-dev \
git \
gperf \
icu-dev \
libjpeg-turbo-dev \
libpng-dev \
libressl-dev \
pcre-dev \
py-setuptools \
zlib-dev \
;
WORKDIR /usr/src
RUN git clone -b ${MOD_PAGESPEED_TAG} \
--recurse-submodules \
--depth=1 \
-c advice.detachedHead=false \
-j`nproc` \
https://github.com/apache/incubator-pagespeed-mod.git \
modpagespeed \
;
WORKDIR /usr/src/modpagespeed
COPY patches/modpagespeed/*.patch ./
RUN for i in *.patch; do printf "\r\nApplying patch ${i%%.*}\r\n"; patch -p1 < $i || exit 1; done
WORKDIR /usr/src/modpagespeed/tools/gyp
RUN ./setup.py install
WORKDIR /usr/src/modpagespeed
RUN build/gyp_chromium --depth=. \
-D use_system_libs=1 \
&& \
cd /usr/src/modpagespeed/pagespeed/automatic && \
make psol BUILDTYPE=Release \
CFLAGS+="-I/usr/include/apr-1" \
CXXFLAGS+="-I/usr/include/apr-1 -DUCHAR_TYPE=uint16_t" \
-j`nproc` \
;
RUN mkdir -p /usr/src/ngxpagespeed/psol/lib/Release/linux/x64 && \
mkdir -p /usr/src/ngxpagespeed/psol/include/out/Release && \
cp -R out/Release/obj /usr/src/ngxpagespeed/psol/include/out/Release/ && \
cp -R pagespeed/automatic/pagespeed_automatic.a /usr/src/ngxpagespeed/psol/lib/Release/linux/x64/ && \
cp -R net \
pagespeed \
testing \
third_party \
url \
/usr/src/ngxpagespeed/psol/include/ \
;
##########################################
# Build Nginx with support for PageSpeed #
##########################################
FROM alpine:$ALPINE_VERSION AS nginx
# Check https://github.com/apache/incubator-pagespeed-ngx/tags
ARG NGX_PAGESPEED_TAG=v1.13.35.2-stable
# Check http://nginx.org/en/download.html for the latest version.
ARG NGINX_VERSION=1.15.6
ARG NGINX_PGPKEY=520A9993A1C052F8
ARG NGINX_BUILD_CONFIG="\
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-compat \
--with-file-aio \
--with-http_v2_module \
"
RUN apk add --no-cache \
apr-dev \
apr-util-dev \
build-base \
ca-certificates \
gd-dev \
geoip-dev \
git \
gnupg \
icu-dev \
libjpeg-turbo-dev \
libpng-dev \
libxslt-dev \
linux-headers \
libressl-dev \
pcre-dev \
tar \
zlib-dev \
;
WORKDIR /usr/src
RUN git clone -b ${NGX_PAGESPEED_TAG} \
--recurse-submodules \
--shallow-submodules \
--depth=1 \
-c advice.detachedHead=false \
-j`nproc` \
https://github.com/apache/incubator-pagespeed-ngx.git \
ngxpagespeed \
;
RUN wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz.asc && \
(gpg --keyserver ha.pool.sks-keyservers.net --keyserver-options timeout=10 --recv-keys ${NGINX_PGPKEY} || \
gpg --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options timeout=10 --recv-keys ${NGINX_PGPKEY} || \
gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --keyserver-options timeout=10 --recv-keys $NGINX_PGPKEY} ) && \
gpg --trusted-key ${NGINX_PGPKEY} --verify nginx-${NGINX_VERSION}.tar.gz.asc
COPY --from=pagespeed /usr/src/ngxpagespeed /usr/src/ngxpagespeed/
WORKDIR /usr/src/nginx
RUN tar zxf ../nginx-${NGINX_VERSION}.tar.gz --strip-components=1 -C . && \
./configure \
${NGINX_BUILD_CONFIG} \
--add-module=/usr/src/ngxpagespeed \
--with-ld-opt="-Wl,-z,relro,--start-group -lapr-1 -laprutil-1 -licudata -licuuc -lpng -lturbojpeg -ljpeg" \
&& \
make install -j`nproc`
RUN rm -rf /etc/nginx/html/ && \
mkdir /etc/nginx/conf.d/ && \
mkdir -p /usr/share/nginx/html/ && \
sed -i 's|^</body>|<p><a href="https://www.ngxpagespeed.com/"><img src="pagespeed.png" title="Nginx module for rewriting web pages to reduce latency and bandwidth" /></a></p>\n</body>|' html/index.html && \
install -m644 html/index.html /usr/share/nginx/html/ && \
install -m644 html/50x.html /usr/share/nginx/html/ && \
ln -s ../../usr/lib/nginx/modules /etc/nginx/modules && \
strip /usr/sbin/nginx* \
/usr/lib/nginx/modules/*.so \
;
COPY conf/nginx.conf /etc/nginx/nginx.conf
COPY conf/nginx.vh.default.conf /etc/nginx/conf.d/default.conf
COPY pagespeed.png /usr/share/nginx/html/
##########################################
# Combine everything with minimal layers #
##########################################
FROM alpine:$ALPINE_VERSION
LABEL maintainer="Nico Berlee <nico.berlee@on2it.net>" \
version.mod-pagespeed="1.13.35.2" \
version.nginx="1.15.6" \
version.ngx-pagespeed="1.13.35.2"
COPY --from=pagespeed /usr/bin/envsubst /usr/local/bin
COPY --from=nginx /usr/sbin/nginx /usr/sbin/nginx
COPY --from=nginx /usr/lib/nginx/modules/ /usr/lib/nginx/modules/
COPY --from=nginx /etc/nginx /etc/nginx
COPY --from=nginx /usr/share/nginx/html/ /usr/share/nginx/html/
RUN apk --no-cache upgrade && \
scanelf --needed --nobanner --format '%n#p' /usr/sbin/nginx /usr/lib/nginx/modules/*.so /usr/local/bin/envsubst \
| tr ',' '\n' \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
| xargs apk add --no-cache \
&& \
apk add --no-cache tzdata
RUN addgroup -S nginx && \
adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx && \
install -g nginx -o nginx -d /var/cache/ngx_pagespeed && \
mkdir -p /var/log/nginx && \
ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
@@ -0,0 +1,32 @@
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
@@ -0,0 +1,57 @@
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
pagespeed on;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/cache/ngx_pagespeed;
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

@@ -0,0 +1,31 @@
--- a/pagespeed/automatic/Makefile
+++ b/pagespeed/automatic/Makefile
@@ -146,8 +146,6 @@
pagespeed/libpagespeed_thread.a \
pagespeed/libpthread_system.a \
pagespeed/libutil.a \
- third_party/apr/libapr.a \
- third_party/aprutil/libaprutil.a \
third_party/base64/libbase64.a \
third_party/chromium/src/base/third_party/dynamic_annotations/libdynamic_annotations.a \
third_party/css_parser/libcss_parser.a \
@@ -163,18 +161,11 @@
third_party/grpc/libgrpc_core.a \
third_party/grpc/libgrpc_cpp.a \
third_party/hiredis/libhiredis.a \
- third_party/icu/libicudata.a \
- third_party/icu/libicuuc.a \
third_party/jsoncpp/libjsoncpp.a \
- third_party/libjpeg_turbo/libjpeg.a \
- third_party/libjpeg_turbo/src/libjpeg_turbo.a \
- third_party/libpng/libpng.a \
third_party/optipng/libopngreduc.a \
third_party/protobuf/libprotobuf_full_do_not_use.a \
third_party/re2/libre2.a \
- third_party/serf/libopenssl.a \
third_party/serf/libserf.a \
- third_party/zlib/libzlib.a \
url/liburl_lib.a
# The 'gclient' build flow uses 'xcodebuild' on Mac and 'make' on Linux.
@@ -0,0 +1,141 @@
From 7ea8d5fc141c7067c54ffa2b9fbc552c15089ca6 Mon Sep 17 00:00:00 2001
From: ashishk-1 <ashish.k@gdbtech.in>
Date: Thu, 18 Jan 2018 22:14:05 +0530
Subject: [PATCH] Upgrading libpng library to version 1.6 (#1724)
---
net/instaweb/rewriter/image.cc | 8 ++++++++
pagespeed/kernel/image/gif_reader.cc | 4 ++--
pagespeed/kernel/image/image_converter.cc | 6 ++++++
pagespeed/kernel/image/png_optimizer_test.cc | 6 ++++++
third_party/libpng/libpng.gyp | 26 +++++++++++++++++++++++---
third_party/libpng/src | 2 +-
6 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/net/instaweb/rewriter/image.cc b/net/instaweb/rewriter/image.cc
index 4f631182a..bb67bba35 100644
--- a/net/instaweb/rewriter/image.cc
+++ b/net/instaweb/rewriter/image.cc
@@ -21,6 +21,14 @@
#include <algorithm>
#include <cstddef>
+extern "C" {
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
+} // extern "C"
+
#include "base/logging.h"
#include "net/instaweb/rewriter/cached_result.pb.h"
#include "net/instaweb/rewriter/public/image_data_lookup.h"
diff --git a/pagespeed/kernel/image/gif_reader.cc b/pagespeed/kernel/image/gif_reader.cc
index 7de69b3d7..bb0bc9cfc 100644
--- a/pagespeed/kernel/image/gif_reader.cc
+++ b/pagespeed/kernel/image/gif_reader.cc
@@ -411,8 +411,8 @@ bool ReadGifToPng(GifFileType* gif_file,
png_uint_32 height = png_get_image_height(paletted_png_ptr,
paletted_info_ptr);
for (png_uint_32 row = 1; row < height; ++row) {
- memcpy(paletted_info_ptr->row_pointers[row],
- paletted_info_ptr->row_pointers[0],
+ memcpy(row_pointers[row],
+ row_pointers[0],
row_size);
}
diff --git a/pagespeed/kernel/image/image_converter.cc b/pagespeed/kernel/image/image_converter.cc
index d796b5065..84b7aff74 100644
--- a/pagespeed/kernel/image/image_converter.cc
+++ b/pagespeed/kernel/image/image_converter.cc
@@ -30,6 +30,12 @@ extern "C" {
#else
#include "third_party/libpng/src/png.h"
#endif
+
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
} // extern "C"
#include "base/logging.h"
diff --git a/pagespeed/kernel/image/png_optimizer_test.cc b/pagespeed/kernel/image/png_optimizer_test.cc
index 9ad915aff..3faa526a8 100644
--- a/pagespeed/kernel/image/png_optimizer_test.cc
+++ b/pagespeed/kernel/image/png_optimizer_test.cc
@@ -36,6 +36,12 @@ extern "C" {
#else
#include "third_party/libpng/src/png.h"
#endif
+
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
}
namespace {
diff --git a/third_party/libpng/libpng.gyp b/third_party/libpng/libpng.gyp
index cfaafee00..d96a8f74c 100644
--- a/third_party/libpng/libpng.gyp
+++ b/third_party/libpng/libpng.gyp
@@ -22,14 +22,29 @@
'dependencies': [
'../zlib/zlib.gyp:zlib',
],
+ 'actions': [
+ {
+ 'action_name': 'copy_libpngconf_prebuilt',
+ 'inputs' : [],
+ 'outputs': [''],
+ 'action': [
+ 'cp',
+ '-f',
+ '<(DEPTH)/third_party/libpng/src/scripts/pnglibconf.h.prebuilt',
+ '<(DEPTH)/third_party/libpng/src/pnglibconf.h',
+ ],
+ },
+ ],
'msvs_guid': 'C564F145-9172-42C3-BFCB-6014CA97DBCD',
'sources': [
+ 'src/pngpriv.h',
'src/png.c',
'src/png.h',
'src/pngconf.h',
+ 'src/pngdebug.h',
'src/pngerror.c',
- 'src/pnggccrd.c',
'src/pngget.c',
+ 'src/pnginfo.h',
'src/pngmem.c',
'src/pngpread.c',
'src/pngread.c',
@@ -37,9 +52,8 @@
'src/pngrtran.c',
'src/pngrutil.c',
'src/pngset.c',
+ 'src/pngstruct.h',
'src/pngtrans.c',
- 'src/pngusr.h',
- 'src/pngvcrd.c',
'src/pngwio.c',
'src/pngwrite.c',
'src/pngwtran.c',
@@ -54,6 +68,12 @@
# doesn't like that. This define tells libpng to not
# complain about our inclusion of setjmp.h.
'PNG_SKIP_SETJMP_CHECK',
+
+ # The PNG_FREE_ME_SUPPORTED define was dropped in libpng
+ # 1.4.0beta78, with its behavior becoming the default
+ # behavior.
+ # Hence, we define it ourselves for version >= 1.4.0
+ 'PNG_FREE_ME_SUPPORTED',
],
},
'export_dependent_settings': [
@@ -0,0 +1,11 @@
--- a/pagespeed/kernel/thread/pthread_rw_lock.cc
+++ b/pagespeed/kernel/thread/pthread_rw_lock.cc
@@ -31,7 +31,7 @@
//
// Other OS's (FreeBSD, Darwin, OpenSolaris) documentation suggests
// that they prefer writers by default.
-#ifdef linux
+#if defined(linux) && defined(__GLIBC__)
pthread_rwlockattr_setkind_np(&attr_,
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
#endif
@@ -0,0 +1,13 @@
--- a/pagespeed/automatic/rename_c_symbols.sh
+++ b/pagespeed/automatic/rename_c_symbols.sh
@@ -24,8 +24,8 @@
set -e # exit script if any command returns an error
set -u # exit the script if any variable is uninitialized
-IN=$(readlink -f $1)
-OUT=$(readlink -f $2)
+IN=$1
+OUT=$2
# Get a list of defined non-C++ symbols that are global and not weak.
# _Z is used at start of C++-mangled symbol names.
@@ -0,0 +1,64 @@
--- a/third_party/chromium/src/base/debug/stack_trace_posix.cc
+++ b/third_party/chromium/src/base/debug/stack_trace_posix.cc
@@ -5,7 +5,9 @@
#include "base/debug/stack_trace.h"
#include <errno.h>
+#if defined(HAVE_BACKTRACE)
#include <execinfo.h>
+#endif
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
@@ -64,7 +66,7 @@
// Note: code in this function is NOT async-signal safe (std::string uses
// malloc internally).
-#if defined(__GLIBCXX__)
+#if defined(__GLIBCXX__) && defined(HAVE_BACKTRACE)
std::string::size_type search_from = 0;
while (search_from < text->size()) {
@@ -145,7 +147,7 @@
handler->HandleOutput("\n");
}
-#else
+#elif defined(HAVE_BACKTRACE)
bool printed = false;
// Below part is async-signal unsafe (uses malloc), so execute it only
@@ -469,23 +471,31 @@
StackTrace::StackTrace() {
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.
-
+#if defined(HAVE_BACKTRACE)
// Though the backtrace API man page does not list any possible negative
// return values, we take no chance.
count_ = std::max(backtrace(trace_, arraysize(trace_)), 0);
+#else
+ count_ = 0;
+#endif
}
void StackTrace::Print() const {
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.
-
+#if defined(HAVE_BACKTRACE)
PrintBacktraceOutputHandler handler;
ProcessBacktrace(trace_, count_, &handler);
+#endif
}
void StackTrace::OutputToStream(std::ostream* os) const {
+#if !defined(HAVE_BACKTRACE)
+(*os) << "(stack trace not supported)\n";
+#else
StreamBacktraceOutputHandler handler(os);
ProcessBacktrace(trace_, count_, &handler);
+#endif
}
namespace internal {
+235
View File
@@ -0,0 +1,235 @@
ARG ALPINE_VERSION=edge
########################
# Build pagespeed psol #
########################
FROM alpine:$ALPINE_VERSION as pagespeed
# Check https://github.com/apache/incubator-pagespeed-mod/tags
ARG MOD_PAGESPEED_TAG=v1.13.35.2
RUN apk add --no-cache \
apache2-dev \
apr-dev \
apr-util-dev \
build-base \
curl \
gettext-dev \
git \
gperf \
icu-dev \
libjpeg-turbo-dev \
libpng-dev \
libressl-dev \
pcre-dev \
py-setuptools \
zlib-dev \
;
WORKDIR /usr/src
RUN git clone -b ${MOD_PAGESPEED_TAG} \
--recurse-submodules \
--depth=1 \
-c advice.detachedHead=false \
-j`nproc` \
https://github.com/apache/incubator-pagespeed-mod.git \
modpagespeed \
;
WORKDIR /usr/src/modpagespeed
COPY patches/modpagespeed/*.patch ./
RUN for i in *.patch; do printf "\r\nApplying patch ${i%%.*}\r\n"; patch -p1 < $i || exit 1; done
WORKDIR /usr/src/modpagespeed/tools/gyp
RUN ./setup.py install
WORKDIR /usr/src/modpagespeed
RUN build/gyp_chromium --depth=. \
-D use_system_libs=1 \
&& \
cd /usr/src/modpagespeed/pagespeed/automatic && \
make psol BUILDTYPE=Release \
CFLAGS+="-I/usr/include/apr-1" \
CXXFLAGS+="-I/usr/include/apr-1 -DUCHAR_TYPE=uint16_t" \
-j`nproc` \
;
RUN mkdir -p /usr/src/ngxpagespeed/psol/lib/Release/linux/x64 && \
mkdir -p /usr/src/ngxpagespeed/psol/include/out/Release && \
cp -R out/Release/obj /usr/src/ngxpagespeed/psol/include/out/Release/ && \
cp -R pagespeed/automatic/pagespeed_automatic.a /usr/src/ngxpagespeed/psol/lib/Release/linux/x64/ && \
cp -R net \
pagespeed \
testing \
third_party \
url \
/usr/src/ngxpagespeed/psol/include/ \
;
##########################################
# Build Nginx with support for PageSpeed #
##########################################
FROM alpine:$ALPINE_VERSION AS nginx
# Check https://github.com/apache/incubator-pagespeed-ngx/tags
ARG NGX_PAGESPEED_TAG=v1.13.35.2-stable
# Check http://nginx.org/en/download.html for the latest version.
ARG NGINX_VERSION=1.14.1
ARG NGINX_PGPKEY=520A9993A1C052F8
ARG NGINX_BUILD_CONFIG="\
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-compat \
--with-file-aio \
--with-http_v2_module \
"
RUN apk add --no-cache \
apr-dev \
apr-util-dev \
build-base \
ca-certificates \
gd-dev \
geoip-dev \
git \
gnupg \
icu-dev \
libjpeg-turbo-dev \
libpng-dev \
libxslt-dev \
linux-headers \
libressl-dev \
pcre-dev \
tar \
zlib-dev \
;
WORKDIR /usr/src
RUN git clone -b ${NGX_PAGESPEED_TAG} \
--recurse-submodules \
--shallow-submodules \
--depth=1 \
-c advice.detachedHead=false \
-j`nproc` \
https://github.com/apache/incubator-pagespeed-ngx.git \
ngxpagespeed \
;
RUN wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz.asc && \
(gpg --keyserver ha.pool.sks-keyservers.net --keyserver-options timeout=10 --recv-keys ${NGINX_PGPKEY} || \
gpg --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options timeout=10 --recv-keys ${NGINX_PGPKEY} || \
gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --keyserver-options timeout=10 --recv-keys $NGINX_PGPKEY} ) && \
gpg --trusted-key ${NGINX_PGPKEY} --verify nginx-${NGINX_VERSION}.tar.gz.asc
COPY --from=pagespeed /usr/src/ngxpagespeed /usr/src/ngxpagespeed/
WORKDIR /usr/src/nginx
RUN tar zxf ../nginx-${NGINX_VERSION}.tar.gz --strip-components=1 -C .
COPY patches/ngx/*.patch ./
RUN for i in *.patch; do printf "\r\nApplying patch ${i%%.*}\r\n"; patch -p1 < $i || exit 1; done
RUN ./configure \
${NGINX_BUILD_CONFIG} \
--add-module=/usr/src/ngxpagespeed \
--with-ld-opt="-Wl,-z,relro,--start-group -lapr-1 -laprutil-1 -licudata -licuuc -lpng -lturbojpeg -ljpeg" \
&& \
make install -j`nproc`
RUN rm -rf /etc/nginx/html/ && \
mkdir /etc/nginx/conf.d/ && \
mkdir -p /usr/share/nginx/html/ && \
sed -i 's|^</body>|<p><a href="https://www.ngxpagespeed.com/"><img src="pagespeed.png" title="Nginx module for rewriting web pages to reduce latency and bandwidth" /></a></p>\n</body>|' html/index.html && \
install -m644 html/index.html /usr/share/nginx/html/ && \
install -m644 html/50x.html /usr/share/nginx/html/ && \
ln -s ../../usr/lib/nginx/modules /etc/nginx/modules && \
strip /usr/sbin/nginx* \
/usr/lib/nginx/modules/*.so \
;
COPY conf/nginx.conf /etc/nginx/nginx.conf
COPY conf/nginx.vh.default.conf /etc/nginx/conf.d/default.conf
COPY pagespeed.png /usr/share/nginx/html/
##########################################
# Combine everything with minimal layers #
##########################################
FROM alpine:$ALPINE_VERSION
LABEL maintainer="Nico Berlee <nico.berlee@on2it.net>" \
version.mod-pagespeed="1.13.35.2" \
version.nginx="1.14.1" \
version.ngx-pagespeed="1.13.35.2"
COPY --from=pagespeed /usr/bin/envsubst /usr/local/bin
COPY --from=nginx /usr/sbin/nginx /usr/sbin/nginx
COPY --from=nginx /usr/lib/nginx/modules/ /usr/lib/nginx/modules/
COPY --from=nginx /etc/nginx /etc/nginx
COPY --from=nginx /usr/share/nginx/html/ /usr/share/nginx/html/
RUN apk --no-cache upgrade && \
scanelf --needed --nobanner --format '%n#p' /usr/sbin/nginx /usr/lib/nginx/modules/*.so /usr/local/bin/envsubst \
| tr ',' '\n' \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
| xargs apk add --no-cache \
&& \
apk add --no-cache tzdata
RUN addgroup -S nginx && \
adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx && \
install -g nginx -o nginx -d /var/cache/ngx_pagespeed && \
mkdir -p /var/log/nginx && \
ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
@@ -0,0 +1,32 @@
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
@@ -0,0 +1,57 @@
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
pagespeed on;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/cache/ngx_pagespeed;
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

@@ -0,0 +1,31 @@
--- a/pagespeed/automatic/Makefile
+++ b/pagespeed/automatic/Makefile
@@ -146,8 +146,6 @@
pagespeed/libpagespeed_thread.a \
pagespeed/libpthread_system.a \
pagespeed/libutil.a \
- third_party/apr/libapr.a \
- third_party/aprutil/libaprutil.a \
third_party/base64/libbase64.a \
third_party/chromium/src/base/third_party/dynamic_annotations/libdynamic_annotations.a \
third_party/css_parser/libcss_parser.a \
@@ -163,18 +161,11 @@
third_party/grpc/libgrpc_core.a \
third_party/grpc/libgrpc_cpp.a \
third_party/hiredis/libhiredis.a \
- third_party/icu/libicudata.a \
- third_party/icu/libicuuc.a \
third_party/jsoncpp/libjsoncpp.a \
- third_party/libjpeg_turbo/libjpeg.a \
- third_party/libjpeg_turbo/src/libjpeg_turbo.a \
- third_party/libpng/libpng.a \
third_party/optipng/libopngreduc.a \
third_party/protobuf/libprotobuf_full_do_not_use.a \
third_party/re2/libre2.a \
- third_party/serf/libopenssl.a \
third_party/serf/libserf.a \
- third_party/zlib/libzlib.a \
url/liburl_lib.a
# The 'gclient' build flow uses 'xcodebuild' on Mac and 'make' on Linux.
@@ -0,0 +1,141 @@
From 7ea8d5fc141c7067c54ffa2b9fbc552c15089ca6 Mon Sep 17 00:00:00 2001
From: ashishk-1 <ashish.k@gdbtech.in>
Date: Thu, 18 Jan 2018 22:14:05 +0530
Subject: [PATCH] Upgrading libpng library to version 1.6 (#1724)
---
net/instaweb/rewriter/image.cc | 8 ++++++++
pagespeed/kernel/image/gif_reader.cc | 4 ++--
pagespeed/kernel/image/image_converter.cc | 6 ++++++
pagespeed/kernel/image/png_optimizer_test.cc | 6 ++++++
third_party/libpng/libpng.gyp | 26 +++++++++++++++++++++++---
third_party/libpng/src | 2 +-
6 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/net/instaweb/rewriter/image.cc b/net/instaweb/rewriter/image.cc
index 4f631182a..bb67bba35 100644
--- a/net/instaweb/rewriter/image.cc
+++ b/net/instaweb/rewriter/image.cc
@@ -21,6 +21,14 @@
#include <algorithm>
#include <cstddef>
+extern "C" {
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
+} // extern "C"
+
#include "base/logging.h"
#include "net/instaweb/rewriter/cached_result.pb.h"
#include "net/instaweb/rewriter/public/image_data_lookup.h"
diff --git a/pagespeed/kernel/image/gif_reader.cc b/pagespeed/kernel/image/gif_reader.cc
index 7de69b3d7..bb0bc9cfc 100644
--- a/pagespeed/kernel/image/gif_reader.cc
+++ b/pagespeed/kernel/image/gif_reader.cc
@@ -411,8 +411,8 @@ bool ReadGifToPng(GifFileType* gif_file,
png_uint_32 height = png_get_image_height(paletted_png_ptr,
paletted_info_ptr);
for (png_uint_32 row = 1; row < height; ++row) {
- memcpy(paletted_info_ptr->row_pointers[row],
- paletted_info_ptr->row_pointers[0],
+ memcpy(row_pointers[row],
+ row_pointers[0],
row_size);
}
diff --git a/pagespeed/kernel/image/image_converter.cc b/pagespeed/kernel/image/image_converter.cc
index d796b5065..84b7aff74 100644
--- a/pagespeed/kernel/image/image_converter.cc
+++ b/pagespeed/kernel/image/image_converter.cc
@@ -30,6 +30,12 @@ extern "C" {
#else
#include "third_party/libpng/src/png.h"
#endif
+
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
} // extern "C"
#include "base/logging.h"
diff --git a/pagespeed/kernel/image/png_optimizer_test.cc b/pagespeed/kernel/image/png_optimizer_test.cc
index 9ad915aff..3faa526a8 100644
--- a/pagespeed/kernel/image/png_optimizer_test.cc
+++ b/pagespeed/kernel/image/png_optimizer_test.cc
@@ -36,6 +36,12 @@ extern "C" {
#else
#include "third_party/libpng/src/png.h"
#endif
+
+#ifdef USE_SYSTEM_ZLIB
+#include "zlib.h"
+#else
+#include "third_party/zlib/zlib.h"
+#endif
}
namespace {
diff --git a/third_party/libpng/libpng.gyp b/third_party/libpng/libpng.gyp
index cfaafee00..d96a8f74c 100644
--- a/third_party/libpng/libpng.gyp
+++ b/third_party/libpng/libpng.gyp
@@ -22,14 +22,29 @@
'dependencies': [
'../zlib/zlib.gyp:zlib',
],
+ 'actions': [
+ {
+ 'action_name': 'copy_libpngconf_prebuilt',
+ 'inputs' : [],
+ 'outputs': [''],
+ 'action': [
+ 'cp',
+ '-f',
+ '<(DEPTH)/third_party/libpng/src/scripts/pnglibconf.h.prebuilt',
+ '<(DEPTH)/third_party/libpng/src/pnglibconf.h',
+ ],
+ },
+ ],
'msvs_guid': 'C564F145-9172-42C3-BFCB-6014CA97DBCD',
'sources': [
+ 'src/pngpriv.h',
'src/png.c',
'src/png.h',
'src/pngconf.h',
+ 'src/pngdebug.h',
'src/pngerror.c',
- 'src/pnggccrd.c',
'src/pngget.c',
+ 'src/pnginfo.h',
'src/pngmem.c',
'src/pngpread.c',
'src/pngread.c',
@@ -37,9 +52,8 @@
'src/pngrtran.c',
'src/pngrutil.c',
'src/pngset.c',
+ 'src/pngstruct.h',
'src/pngtrans.c',
- 'src/pngusr.h',
- 'src/pngvcrd.c',
'src/pngwio.c',
'src/pngwrite.c',
'src/pngwtran.c',
@@ -54,6 +68,12 @@
# doesn't like that. This define tells libpng to not
# complain about our inclusion of setjmp.h.
'PNG_SKIP_SETJMP_CHECK',
+
+ # The PNG_FREE_ME_SUPPORTED define was dropped in libpng
+ # 1.4.0beta78, with its behavior becoming the default
+ # behavior.
+ # Hence, we define it ourselves for version >= 1.4.0
+ 'PNG_FREE_ME_SUPPORTED',
],
},
'export_dependent_settings': [
@@ -0,0 +1,11 @@
--- a/pagespeed/kernel/thread/pthread_rw_lock.cc
+++ b/pagespeed/kernel/thread/pthread_rw_lock.cc
@@ -31,7 +31,7 @@
//
// Other OS's (FreeBSD, Darwin, OpenSolaris) documentation suggests
// that they prefer writers by default.
-#ifdef linux
+#if defined(linux) && defined(__GLIBC__)
pthread_rwlockattr_setkind_np(&attr_,
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
#endif
@@ -0,0 +1,13 @@
--- a/pagespeed/automatic/rename_c_symbols.sh
+++ b/pagespeed/automatic/rename_c_symbols.sh
@@ -24,8 +24,8 @@
set -e # exit script if any command returns an error
set -u # exit the script if any variable is uninitialized
-IN=$(readlink -f $1)
-OUT=$(readlink -f $2)
+IN=$1
+OUT=$2
# Get a list of defined non-C++ symbols that are global and not weak.
# _Z is used at start of C++-mangled symbol names.
@@ -0,0 +1,64 @@
--- a/third_party/chromium/src/base/debug/stack_trace_posix.cc
+++ b/third_party/chromium/src/base/debug/stack_trace_posix.cc
@@ -5,7 +5,9 @@
#include "base/debug/stack_trace.h"
#include <errno.h>
+#if defined(HAVE_BACKTRACE)
#include <execinfo.h>
+#endif
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
@@ -64,7 +66,7 @@
// Note: code in this function is NOT async-signal safe (std::string uses
// malloc internally).
-#if defined(__GLIBCXX__)
+#if defined(__GLIBCXX__) && defined(HAVE_BACKTRACE)
std::string::size_type search_from = 0;
while (search_from < text->size()) {
@@ -145,7 +147,7 @@
handler->HandleOutput("\n");
}
-#else
+#elif defined(HAVE_BACKTRACE)
bool printed = false;
// Below part is async-signal unsafe (uses malloc), so execute it only
@@ -469,23 +471,31 @@
StackTrace::StackTrace() {
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.
-
+#if defined(HAVE_BACKTRACE)
// Though the backtrace API man page does not list any possible negative
// return values, we take no chance.
count_ = std::max(backtrace(trace_, arraysize(trace_)), 0);
+#else
+ count_ = 0;
+#endif
}
void StackTrace::Print() const {
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.
-
+#if defined(HAVE_BACKTRACE)
PrintBacktraceOutputHandler handler;
ProcessBacktrace(trace_, count_, &handler);
+#endif
}
void StackTrace::OutputToStream(std::ostream* os) const {
+#if !defined(HAVE_BACKTRACE)
+(*os) << "(stack trace not supported)\n";
+#else
StreamBacktraceOutputHandler handler(os);
ProcessBacktrace(trace_, count_, &handler);
+#endif
}
namespace internal {
@@ -0,0 +1,190 @@
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index bc43f53ed9..3eec1b7dd0 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -3264,7 +3264,8 @@ ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf,
return NGX_ERROR;
}
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
+ copy->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_copy_len_code;
copy->len = src[i].key.len;
copy = ngx_array_push_n(params->lengths,
@@ -3273,7 +3274,8 @@ ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf,
return NGX_ERROR;
}
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
+ copy->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_copy_len_code;
copy->len = src[i].skip_empty;
diff --git a/src/http/modules/ngx_http_grpc_module.c b/src/http/modules/ngx_http_grpc_module.c
index 837ad9a2ea..300d927047 100644
--- a/src/http/modules/ngx_http_grpc_module.c
+++ b/src/http/modules/ngx_http_grpc_module.c
@@ -4389,7 +4389,8 @@ ngx_http_grpc_init_headers(ngx_conf_t *cf, ngx_http_grpc_loc_conf_t *conf,
return NGX_ERROR;
}
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
+ copy->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_copy_len_code;
copy->len = src[i].key.len;
size = (sizeof(ngx_http_script_copy_code_t)
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
index c9ad638df9..e7f829d653 100644
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -3493,7 +3493,8 @@ ngx_http_proxy_init_headers(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *conf,
return NGX_ERROR;
}
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
+ copy->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_copy_len_code;
copy->len = src[i].key.len;
size = (sizeof(ngx_http_script_copy_code_t)
diff --git a/src/http/modules/ngx_http_scgi_module.c b/src/http/modules/ngx_http_scgi_module.c
index 3fb227b28c..9bd45bd136 100644
--- a/src/http/modules/ngx_http_scgi_module.c
+++ b/src/http/modules/ngx_http_scgi_module.c
@@ -1724,7 +1724,8 @@ ngx_http_scgi_init_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
return NGX_ERROR;
}
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
+ copy->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_copy_len_code;
copy->len = src[i].key.len + 1;
copy = ngx_array_push_n(params->lengths,
@@ -1733,7 +1734,8 @@ ngx_http_scgi_init_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
return NGX_ERROR;
}
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
+ copy->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_copy_len_code;
copy->len = src[i].skip_empty;
diff --git a/src/http/modules/ngx_http_uwsgi_module.c b/src/http/modules/ngx_http_uwsgi_module.c
index 124da4db56..238bcf8a3b 100644
--- a/src/http/modules/ngx_http_uwsgi_module.c
+++ b/src/http/modules/ngx_http_uwsgi_module.c
@@ -1987,7 +1987,8 @@ ngx_http_uwsgi_init_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf,
return NGX_ERROR;
}
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
+ copy->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_copy_len_code;
copy->len = src[i].key.len;
copy = ngx_array_push_n(params->lengths,
@@ -1996,7 +1997,8 @@ ngx_http_uwsgi_init_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf,
return NGX_ERROR;
}
- copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
+ copy->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_copy_len_code;
copy->len = src[i].skip_empty;
diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c
index 96f3ec6965..1a87735617 100644
--- a/src/http/ngx_http_script.c
+++ b/src/http/ngx_http_script.c
@@ -695,7 +695,8 @@ ngx_http_script_add_copy_code(ngx_http_script_compile_t *sc, ngx_str_t *value,
return NGX_ERROR;
}
- code->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
+ code->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_copy_len_code;
code->len = len;
size = (sizeof(ngx_http_script_copy_code_t) + len + sizeof(uintptr_t) - 1)
@@ -784,7 +785,8 @@ ngx_http_script_add_var_code(ngx_http_script_compile_t *sc, ngx_str_t *name)
return NGX_ERROR;
}
- code->code = (ngx_http_script_code_pt) ngx_http_script_copy_var_len_code;
+ code->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_copy_var_len_code;
code->index = (uintptr_t) index;
code = ngx_http_script_add_code(*sc->values,
@@ -1178,8 +1180,8 @@ ngx_http_script_add_capture_code(ngx_http_script_compile_t *sc, ngx_uint_t n)
return NGX_ERROR;
}
- code->code = (ngx_http_script_code_pt)
- ngx_http_script_copy_capture_len_code;
+ code->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_copy_capture_len_code;
code->n = 2 * n;
@@ -1293,7 +1295,8 @@ ngx_http_script_add_full_name_code(ngx_http_script_compile_t *sc)
return NGX_ERROR;
}
- code->code = (ngx_http_script_code_pt) ngx_http_script_full_name_len_code;
+ code->code = (ngx_http_script_code_pt) (void *)
+ ngx_http_script_full_name_len_code;
code->conf_prefix = sc->conf_prefix;
code = ngx_http_script_add_code(*sc->values,
diff --git a/src/stream/ngx_stream_script.c b/src/stream/ngx_stream_script.c
index aa555ca2c1..b00e7086f7 100644
--- a/src/stream/ngx_stream_script.c
+++ b/src/stream/ngx_stream_script.c
@@ -587,7 +587,8 @@ ngx_stream_script_add_copy_code(ngx_stream_script_compile_t *sc,
return NGX_ERROR;
}
- code->code = (ngx_stream_script_code_pt) ngx_stream_script_copy_len_code;
+ code->code = (ngx_stream_script_code_pt) (void *)
+ ngx_stream_script_copy_len_code;
code->len = len;
size = (sizeof(ngx_stream_script_copy_code_t) + len + sizeof(uintptr_t) - 1)
@@ -677,8 +678,8 @@ ngx_stream_script_add_var_code(ngx_stream_script_compile_t *sc, ngx_str_t *name)
return NGX_ERROR;
}
- code->code = (ngx_stream_script_code_pt)
- ngx_stream_script_copy_var_len_code;
+ code->code = (ngx_stream_script_code_pt) (void *)
+ ngx_stream_script_copy_var_len_code;
code->index = (uintptr_t) index;
code = ngx_stream_script_add_code(*sc->values,
@@ -767,8 +768,8 @@ ngx_stream_script_add_capture_code(ngx_stream_script_compile_t *sc,
return NGX_ERROR;
}
- code->code = (ngx_stream_script_code_pt)
- ngx_stream_script_copy_capture_len_code;
+ code->code = (ngx_stream_script_code_pt) (void *)
+ ngx_stream_script_copy_capture_len_code;
code->n = 2 * n;
@@ -859,7 +860,7 @@ ngx_stream_script_add_full_name_code(ngx_stream_script_compile_t *sc)
return NGX_ERROR;
}
- code->code = (ngx_stream_script_code_pt)
+ code->code = (ngx_stream_script_code_pt) (void *)
ngx_stream_script_full_name_len_code;
code->conf_prefix = sc->conf_prefix;
+824
View File
@@ -0,0 +1,824 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
function usage() {
echo "
Usage: build_ngx_pagespeed.sh [options]
Installs ngx_pagespeed and its dependencies. Can optionally build and install
nginx as well. Can be run either as:
bash <(curl -f -L -sS https://ngxpagespeed.com/install) [options]
Or:
git clone git@github.com:pagespeed/ngx_pagespeed.git
cd ngx_pagespeed/
git checkout <branch>
scripts/build_ngx_pagespeed.sh [options]
Options:
-v, --ngx-pagespeed-version <ngx_pagespeed version>
What version of ngx_pagespeed to build. Valid options include:
* latest-beta
* latest-stable
* a version number, such as 1.11.33.4
If you don't specify a version, defaults to latest-stable unless --devel
is specified, in which case it defaults to master.
This option doesn't make sense if we're running within an existing
ngx_pagespeed checkout.
-n, --nginx-version <nginx version>
What version of nginx to build. If not set, this script only prepares the
ngx_pagespeed module, and expects you to handle including it when you
build nginx.
If you pass in 'latest' then this script scrapes the nginx download page
and attempts to determine the latest version automatically.
-m, --dynamic-module
Build ngx_pagespeed as a dynamic module.
-b, --builddir <directory>
Where to build. Defaults to \$HOME.
-p, --no-deps-check
By default, this script checks for the packages it depends on and tries to
install them. If you have installed dependencies from source or are on a
non-deb non-rpm system, this won't work. In that case, install the
dependencies yourself and pass --no-deps-check.
-s, --psol-from-source
Build PSOL from source instead of downloading a pre-built binary module.
-l, --devel
Sets up a development environment in ngx_pagespeed/nginx, building with
testing-only dependencies. Includes --psol-from-source, conflicts with
--nginx-version. Uses a 'git clone' checkout for ngx_pagespeed and nginx
instead of downloading a tarball.
-t, --build-type
When building PSOL from source, what to tell it for BUILD_TYPE. Defaults
to 'Release' unless --devel is set in which case it defaults to 'Debug'.
-y, --assume-yes
Assume the answer to all prompts is 'yes, please continue'. Intended for
automated usage, such as buildbots.
-a, --additional-nginx-configure-arguments
When running ./configure for nginx, you may want to specify additional
arguments, such as --with-http_ssl_module. By default this script will
pause and prompt you for them, but this option lets you pass them in. For
example, you might do:
-a '--with-http_ssl_module --with-cc-opt=\"-I /usr/local/include\"'
-d, --dryrun
Don't make any changes to the system, just print what changes you
would have made.
-h, --help
Print this message and exit."
}
RED=31
GREEN=32
YELLOW=33
function begin_color() {
color="$1"
echo -e -n "\e[${color}m"
}
function end_color() {
echo -e -n "\e[0m"
}
function echo_color() {
color="$1"
shift
begin_color "$color"
echo "$@"
end_color
}
function error() {
local error_message="$@"
echo_color "$RED" -n "Error: " >&2
echo "$@" >&2
}
# Prints an error message and exits with an error code.
function fail() {
error "$@"
# Normally I'd use $0 in "usage" here, but since most people will be running
# this via curl, that wouldn't actually give something useful.
echo >&2
echo "For usage information, run this script with --help" >&2
exit 1
}
function status() {
echo_color "$GREEN" "$@"
}
# Intended to be called as:
# bash <(curl dl.google.com/.../build_ngx_pagespeed.sh) <args>
# If we set -e or -u then users of this script will see it silently exit on
# failure. Instead we need to check the exit status of each command manually.
# The run function handles exit-status checking for system-changing commands.
# Additionally, this allows us to easily have a dryrun mode where we don't
# actually make any changes.
INITIAL_ENV=$(printenv | sort)
function run() {
if "$DRYRUN"; then
echo_color "$YELLOW" -n "would run"
echo " $@"
env_differences=$(comm -13 <(echo "$INITIAL_ENV") <(printenv | sort))
if [ -n "$env_differences" ]; then
echo " with the following additional environment variables:"
echo "$env_differences" | sed 's/^/ /'
fi
else
if ! "$@"; then
error "Failure running '$@', exiting."
exit 1
fi
fi
}
function redhat_is_installed() {
local package_name="$1"
rpm -qa $package_name | grep -q .
}
function debian_is_installed() {
local package_name="$1"
dpkg -l $package_name | grep ^ii | grep -q .
}
function version_sort() {
# We'd rather use sort -V, but that's not available on Centos 5. This works
# for versions in the form A.B.C.D or shorter, which is enough for our use.
sort -t '.' -k 1,1 -k 2,2 -k 3,3 -k 4,4 -g
}
# Compare two numeric versions in the form "A.B.C". Works with version numbers
# having up to four components, since that's enough to handle both nginx (3) and
# ngx_pagespeed (4).
function version_older_than() {
local test_version="$1"
local compare_to="$2"
local older_version=$(echo $@ | tr ' ' '\n' | version_sort | head -n 1)
test "$older_version" != "$compare_to"
}
function determine_latest_nginx_version() {
# Scrape nginx's download page to try to find the most recent nginx version.
nginx_download_url="https://nginx.org/en/download.html"
function report_error() {
fail "
Couldn't automatically determine the latest nginx version: failed to $@
$nginx_download_url"
}
nginx_download_page=$(curl -sS --fail "$nginx_download_url") || \
report_error "download"
download_refs=$(echo "$nginx_download_page" | \
grep -o '/download/nginx-[0-9.]*[.]tar[.]gz') || \
report_error "parse"
versions_available=$(echo "$download_refs" | \
sed -e 's~^/download/nginx-~~' -e 's~\.tar\.gz$~~') || \
report_error "extract versions from"
latest_version=$(echo "$versions_available" | version_sort | tail -n 1) || \
report_error "determine latest version from"
if version_older_than "$latest_version" "1.11.4"; then
fail "
Expected the latest version of nginx to be at least 1.11.4 but found
$latest_version on $nginx_download_url"
fi
echo "$latest_version"
}
# Usage:
# install_dependencies install_pkg_cmd is_pkg_installed_cmd dep1 dep2 ...
#
# install_pkg_cmd is a command to install a dependency
# is_pkg_installed_cmd is a command that returns true if the dependency is
# already installed
# each dependency is a package name
function install_dependencies() {
local install_pkg_cmd="$1"
local is_pkg_installed_cmd="$2"
shift 2
local missing_dependencies=""
for package_name in "$@"; do
if ! $is_pkg_installed_cmd $package_name; then
missing_dependencies+="$package_name "
fi
done
if [ -n "$missing_dependencies" ]; then
status "Detected that we're missing the following depencencies:"
echo " $missing_dependencies"
status "Installing them:"
run sudo $install_pkg_cmd $missing_dependencies
fi
}
function gcc_too_old() {
# We need gcc >= 4.8
local gcc_major_version=$(gcc -dumpversion | awk -F. '{print $1}')
if [ "$gcc_major_version" -lt 4 ]; then
return 0 # too old
elif [ "$gcc_major_version" -gt 4 ]; then
return 1 # plenty new
fi
# It's gcc 4.x, check if x >= 8:
local gcc_minor_version=$(gcc -dumpversion | awk -F. '{print $2}')
test "$gcc_minor_version" -lt 8
}
function continue_or_exit() {
if "$ASSUME_YES"; then
return
fi
local prompt="$1"
echo_color "$YELLOW" -n "$prompt"
read -p " [Y/n] " yn
if [[ "$yn" == N* || "$yn" == n* ]]; then
echo "Cancelled."
exit 0
fi
}
# If a string is very simple we don't need to quote it. But we should quote
# everything else to be safe.
function needs_quoting() {
echo "$@" | grep -q '[^a-zA-Z0-9./_=-]'
}
function escape_for_quotes() {
echo "$@" | sed -e 's~\\~\\\\~g' -e "s~'~\\\\'~g"
}
function quote_arguments() {
local argument_str=""
for argument in "$@"; do
if [ -n "$argument_str" ]; then
argument_str+=" "
fi
if needs_quoting "$argument"; then
argument="'$(escape_for_quotes "$argument")'"
fi
argument_str+="$argument"
done
echo "$argument_str"
}
function build_ngx_pagespeed() {
getopt --test
if [ "$?" != 4 ]; then
# Even Centos 5 and Ubuntu 10 LTS have new-style getopt, so I don't expect
# this to be hit in practice on systems that are actually able to run
# PageSpeed.
fail "Your version of getopt is too old. Exiting with no changes made."
fi
opts=$(getopt -o v:n:mb:pslt:ya:dh \
--longoptions ngx-pagespeed-version:,nginx-version:,dynamic-module \
--longoptions buildir:,no-deps-check,psol-from-source,devel,build-type: \
--longoptions assume-yes,additional-nginx-configure-arguments:,dryrun,help \
-n "$(basename "$0")" -- "$@")
if [ $? != 0 ]; then
usage
exit 1
fi
eval set -- "$opts"
NPS_VERSION="DEFAULT"
NGINX_VERSION=""
BUILDDIR="$HOME"
DO_DEPS_CHECK=true
PSOL_FROM_SOURCE=false
DEVEL=false
BUILD_TYPE=""
ASSUME_YES=false
DRYRUN=false
DYNAMIC_MODULE=false
while true; do
case "$1" in
-v | --ngx-pagespeed-version) shift
NPS_VERSION="$1"
shift
;;
-n | --nginx-version) shift
NGINX_VERSION="$1"
shift
;;
-m | --dynamic-module) shift
DYNAMIC_MODULE=true
;;
-b | --builddir) shift
BUILDDIR="$1"
shift
;;
-p | --no-deps-check) shift
DO_DEPS_CHECK=false
;;
-s | --psol-from-source) shift
PSOL_FROM_SOURCE=true
;;
-l | --devel) shift
DEVEL=true
;;
-t | --build-type) shift
BUILD_TYPE="$1"
shift
;;
-y | --assume-yes) shift
ASSUME_YES="true"
;;
-a | --additional-nginx-configure-arguments) shift
ADDITIONAL_NGINX_CONFIGURE_ARGUMENTS="$1"
shift
;;
-d | --dryrun) shift
DRYRUN="true"
;;
-h | --help) shift
usage
exit 0
;;
--) shift
break
;;
*)
echo "Invalid argument: $1"
usage
exit 1
;;
esac
done
USE_GIT_CHECKOUT="$DEVEL"
ALREADY_CHECKED_OUT=false
if [ -e PSOL_BINARY_URL ]; then
status "Detected that we're running in an existing ngx_pagespeed checkout."
USE_GIT_CHECKOUT=true
ALREADY_CHECKED_OUT=true
fi
if "$ALREADY_CHECKED_OUT"; then
if [ "$NPS_VERSION" != "DEFAULT" ]; then
fail \
"The --ngx-pagespeed-version argument doesn't make sense when running within an existing checkout."
fi
elif [ "$NPS_VERSION" = "DEFAULT" ]; then
if "$DEVEL"; then
NPS_VERSION="master"
else
NPS_VERSION="latest-stable"
fi
fi
if [ ! -d "$BUILDDIR" ]; then
fail "Told to build in $BUILDDIR, but that directory doesn't exist."
fi
BUILD_NGINX=false
if [ -n "$NGINX_VERSION" ]; then
BUILD_NGINX=true
fi
if "$DEVEL"; then
PSOL_FROM_SOURCE=true
BUILD_NGINX=true
if [ -n "$NGINX_VERSION" ]; then
fail \
"The --devel argument conflicts with --nginx. In devel mode we use the version of nginx that's included as a submodule."
fi
if "$DYNAMIC_MODULE"; then
fail "Can't currently build a dynamic module in --devel mode."
fi
fi
if "$PSOL_FROM_SOURCE" && [ -z "$BUILD_TYPE" ]; then
if "$DEVEL"; then
BUILD_TYPE="Debug"
else
BUILD_TYPE="Release"
fi
elif [ -n "$BUILD_TYPE" ]; then
fail "Setting --build-type requires --psol-from-source or --devel."
fi
if [ "$NGINX_VERSION" = "latest" ]; then
# When this function fails it prints the debugging information needed first
# to stderr.
NGINX_VERSION=$(determine_latest_nginx_version) || exit 1
fi
if "$DYNAMIC_MODULE"; then
# Check that ngx_pagespeed and nginx are recent enough to support dynamic
# modules. Unfortunately NPS_VERSION might be a tag, in which case we don't
# know. If it's not a numeric version number, then assume it's recent
# enough and if it's not they'll get an ugly compilation error later.
# Luckily 1.10.33.5 was a while ago now.
#
# I'd like to use =~ here, but they changed syntax between v3 and v4 (quotes
# moved from mandatory to optional to prohibited).
if [[ "${NPS_VERSION#*[^0-9.]}" = "$NPS_VERSION" ]] &&
version_older_than "$NPS_VERSION" "1.10.33.5"; then
fail "
You're trying to build ngx_pagespeed $NPS_VERSION as a dynamic module, but
ngx_pagespeed didn't add support for dynamic modules until 1.10.33.5."
fi
if [ ! -z "NGINX_VERSION" ]; then
if version_older_than "$NGINX_VERSION" "1.9.13"; then
fail "
You're trying to build nginx $NGINX_VERSION as a dynamic module but nginx didn't
add support for dynamic modules in a way compatible with ngx_pagespeed until
1.9.13."
fi
fi
fi
if "$DRYRUN"; then
TEMPDIR="/tmp/output-of-mktemp"
else
TEMPDIR=$(mktemp -d)
function cleanup_tempdir {
rm -rf "$TEMPDIR"
}
trap cleanup_tempdir EXIT
fi
extra_flags=()
# Now make sure our dependencies are installed.
if "$DO_DEPS_CHECK"; then
INSTALL_FLAGS=""
if "$ASSUME_YES"; then
INSTALL_FLAGS="-y"
fi
if [ -f /etc/debian_version ]; then
status "Detected debian-based distro."
install_dependencies "apt-get install ${INSTALL_FLAGS}" debian_is_installed \
build-essential zlib1g-dev libpcre3 libpcre3-dev unzip wget uuid-dev
if gcc_too_old; then
if [ ! -e /usr/lib/gcc-mozilla/bin/gcc ]; then
status "Detected that gcc is older than 4.8. Installing gcc-mozilla"
status "which installs gcc-4.8 into /usr/lib/gcc-mozilla/ and doesn't"
status "affect your global gcc installation."
run sudo apt-get install ${INSTALL_FLAGS} gcc-mozilla
fi
extra_flags=("--with-cc=/usr/lib/gcc-mozilla/bin/gcc" \
"--with-ld-opt=-static-libstdc++")
fi
elif [ -f /etc/redhat-release ]; then
status "Detected redhat-based distro."
install_dependencies "yum install ${INSTALL_FLAGS}" redhat_is_installed \
gcc-c++ pcre-devel zlib-devel make unzip wget libuuid-devel
if gcc_too_old; then
if [ ! -e /opt/rh/devtoolset-2/root/usr/bin/gcc ]; then
redhat_major_version=$(
cat /etc/redhat-release | grep -o -E '[0-9]+' | head -n 1)
if [ "$redhat_major_version" == 5 ]; then
slc_version=5
elif [ "$redhat_major_version" == 6 ]; then
slc_version=6
else
fail "
Unexpected major version $redhat_major_version in /etc/redhat-release:
$(cat /etc/redhat-release) Expected 5 or 6."
fi
status "Detected that gcc is older than 4.8. Scientific Linux"
status "provides a gcc package that installs gcc-4.8 into /opt/ and"
status "doesn't affect your global gcc installation."
slc_key="https://linux.web.cern.ch/linux/scientific6/docs/repository/"
slc_key+="cern/slc6X/i386/RPM-GPG-KEY-cern"
slc_key_out="$TEMPDIR/RPM-GPG-KEY-cern"
run sudo wget "$slc_key" -O "$slc_key_out"
run sudo rpm --import "$slc_key_out"
repo_fname="/etc/yum.repos.d/slc${slc_version}-devtoolset.repo"
if [ -e "$repo_fname" ]; then
fail "Expected $repo_fname not to exist; aborting."
fi
repo_url="https://linux.web.cern.ch/linux/scientific${slc_version}/"
repo_url+="/docs/repository/cern/devtoolset/"
repo_url+="slc${slc_version}-devtoolset.repo"
run sudo wget -O "$repo_fname" "$repo_url"
run sudo yum install ${INSTALL_FLAGS} devtoolset-2-gcc-c++ devtoolset-2-binutils
fi
extra_flags=("--with-cc=/opt/rh/devtoolset-2/root/usr/bin/gcc")
fi
else
fail "
This doesn't appear to be a deb-based distro or an rpm-based one. Not going to
be able to install dependencies. Please install dependencies manually and rerun
with --no-deps-check."
fi
status "Operating system dependencies are all set."
else
status "Not checking whether operating system dependencies are installed."
fi
function delete_if_already_exists() {
if "$DRYRUN"; then return; fi
local directory="$1"
if [ -d "$directory" ]; then
if [ ${#directory} -lt 8 ]; then
fail "
Not deleting $directory; name is suspiciously short. Something is wrong."
fi
continue_or_exit "OK to delete $directory?"
run rm -rf "$directory"
fi
}
# In general, the zip github builds for tag foo unzips to ngx_pagespeed-foo,
# but it looks like they special case vVERSION tags to ngx_pagespeed-VERSION
if [[ "$NPS_VERSION" =~ ^[0-9]*[.][0-9]*[.][0-9]*[.][0-9]*$ ]]; then
# We've been given a numeric version number. This has an associated tag
# in the form vVERSION-beta.
tag_name="v${NPS_VERSION}-beta"
nps_downloaded_fname="ngx_pagespeed-${NPS_VERSION}-beta"
else
# We've been given a tag name, like latest-beta. Download that directly.
tag_name="$NPS_VERSION"
nps_downloaded_fname="ngx_pagespeed-${NPS_VERSION}"
fi
install_dir="this-only-makes-sense-in-devel-mode"
if "$USE_GIT_CHECKOUT"; then
# We're either doing a --devel build, or someone is running us from an
# existing git checkout.
nps_module_dir="$PWD"
install_dir="$nps_module_dir"
if "$ALREADY_CHECKED_OUT"; then
run cd "$nps_module_dir"
else
status "Checking out ngx_pagespeed..."
run git clone "git@github.com:pagespeed/ngx_pagespeed.git" \
"$nps_module_dir"
run cd "$nps_module_dir"
run git checkout "$tag_name"
fi
submodules_dir="$nps_module_dir/testing-dependencies"
if "$DEVEL"; then
status "Downloading dependencies..."
run git submodule update --init --recursive
if [[ "$CONTINUOUS_INTEGRATION" != true ]]; then
status "Switching submodules over to git protocol."
# This lets us push to github by public key.
for config in $(find .git/ -name config) ; do
run sed -i s~https://github.com/~git@github.com:~ $config ;
done
fi
fi
else
nps_baseurl="https://github.com/apache/incubator-pagespeed-ngx/archive"
nps_downloaded="$TEMPDIR/$nps_downloaded_fname.zip"
status "Downloading ngx_pagespeed..."
run wget "$nps_baseurl/$tag_name.zip" -O "$nps_downloaded"
# Read the directory name from the zip, the first line is expected to have it.
nps_module_dir=$(unzip -qql "$nps_downloaded" | head -n1 | tr -s ' ' | cut -d' ' -f5-)
nps_module_dir="$BUILDDIR/${nps_module_dir::-1}"
delete_if_already_exists "$nps_module_dir"
status "Extracting ngx_pagespeed..."
run unzip -q "$nps_downloaded" -d "$BUILDDIR"
run cd "$nps_module_dir"
fi
MOD_PAGESPEED_DIR=""
PSOL_BINARY=""
if "$PSOL_FROM_SOURCE"; then
MOD_PAGESPEED_DIR="$PWD/testing-dependencies/mod_pagespeed"
git submodule update --init --recursive -- "$MOD_PAGESPEED_DIR"
run pushd "$MOD_PAGESPEED_DIR"
if "$DEVEL"; then
if [ ! -d "$HOME/apache2" ]; then
run install/build_development_apache.sh 2.2 prefork
fi
cd devel
run make apache_debug_psol
PSOL_BINARY="$MOD_PAGESPEED_DIR/out/$BUILD_TYPE/pagespeed_automatic.a"
else
if "$DO_DEPS_CHECK"; then
skip_deps_arg=""
else
skip_deps_arg="--skip_deps"
fi
run install/build_psol.sh --skip_tests --skip_packaging "$skip_deps_arg"
PSOL_BINARY="$MOD_PAGESPEED_DIR/pagespeed/automatic/pagespeed_automatic.a"
fi
run popd
else
# Now we need to figure out what precompiled version of PSOL to build
# ngx_pagespeed against.
if "$DRYRUN"; then
psol_url="https://psol.example.com/cant-get-psol-version-in-dry-run.tar.gz"
elif [ -e PSOL_BINARY_URL ]; then
# Releases after 1.11.33.4 there is a PSOL_BINARY_URL file that tells us
# where to look.
psol_url="$(scripts/format_binary_url.sh PSOL_BINARY_URL)"
if [[ "$psol_url" != https://* ]]; then
fail "Got bad psol binary location information: $psol_url"
fi
else
# For past releases we have to grep it from the config file. The url has
# always looked like this, and the config file has contained it since
# before we started tagging our ngx_pagespeed releases.
psol_url="$(grep -o \
"https://dl.google.com/dl/page-speed/psol/[0-9.]*.tar.gz" config)"
if [ -z "$psol_url" ]; then
fail "Couldn't find PSOL url in $PWD/config"
fi
fi
status "Downloading PSOL binary..."
run wget "$psol_url"
status "Extracting PSOL..."
run tar -xzf $(basename "$psol_url") # extracts to psol/
fi
if "$DYNAMIC_MODULE"; then
add_module="--add-dynamic-module=$nps_module_dir"
else
add_module="--add-module=$nps_module_dir"
fi
configure_args=("$add_module" "${extra_flags[@]}")
if "$DEVEL"; then
configure_args=("${configure_args[@]}"
"--prefix=$install_dir/nginx"
"--add-module=$submodules_dir/ngx_cache_purge"
"--add-module=$submodules_dir/ngx_devel_kit"
"--add-module=$submodules_dir/set-misc-nginx-module"
"--add-module=$submodules_dir/headers-more-nginx-module"
"--with-ipv6"
"--with-http_v2_module")
if [ "$BUILD_TYPE" = "Debug" ]; then
configure_args=("${configure_args[@]}" "--with-debug")
fi
fi
echo
if ! "$BUILD_NGINX"; then
# Just prepare the module for them to install.
status "ngx_pagespeed is ready to be built against nginx."
echo "When running ./configure:"
if "$PSOL_FROM_SOURCE"; then
echo " Set the following environment variables:"
echo " MOD_PAGESPEED_DIR=$MOD_PAGESPEED_DIR"
echo " PSOL_BINARY=$PSOL_BINARY"
fi
echo " Give ./configure the following arguments:"
echo " $(quote_arguments "${configure_args[@]}")"
echo
if [ ${#extra_flags[@]} -eq 0 ]; then
echo "If this is for integration with an already-built nginx, make sure"
echo "to include any other arguments you originally passed to"
echo "./configure. You can see these with 'nginx -V'."
else
echo "Note: because we need to set $(quote_arguments "${extra_flags[@]}")"
echo "on this platform, if you want to integrate ngx_pagespeed with an"
echo "already-built nginx you're going to need to rebuild your nginx with"
echo "those flags set."
fi
else
if "$DEVEL"; then
# Use the nginx we loaded as a submodule
nginx_dir="$submodules_dir/nginx"
configure_location="auto"
else
# Download and build the specified nginx version.
nginx_leaf="nginx-${NGINX_VERSION}.tar.gz"
nginx_fname="$TEMPDIR/$nginx_leaf"
status "Downloading nginx..."
run wget "http://nginx.org/download/$nginx_leaf" -O "$nginx_fname"
nginx_dir="$BUILDDIR/nginx-${NGINX_VERSION}/"
delete_if_already_exists "$nginx_dir"
status "Extracting nginx..."
run tar -xzf "$nginx_fname" --directory "$BUILDDIR"
configure_location="."
fi
run cd "$nginx_dir"
configure=("$configure_location/configure" "${configure_args[@]}")
additional_configure_args=""
if [ -z "${ADDITIONAL_NGINX_CONFIGURE_ARGUMENTS+x}" ]; then
if ! "$ASSUME_YES"; then
echo "About to build nginx. Do you have any additional ./configure"
echo "arguments you would like to set? For example, if you would like"
echo "to build nginx with https support give --with-http_ssl_module"
echo "If you don't have any, just press enter."
read -p "> " additional_configure_args
fi
else
additional_configure_args="$ADDITIONAL_NGINX_CONFIGURE_ARGUMENTS"
fi
if [ -n "$additional_configure_args" ]; then
# Split additional_configure_args respecting any internal quotation.
# Otherwise things like --with-cc-opt='-foo -bar' won't work.
eval additional_configure_args=("$additional_configure_args")
configure=("${configure[@]}" "${additional_configure_args[@]}")
fi
echo "About to configure nginx with:"
echo " $(quote_arguments "${configure[@]}")"
continue_or_exit "Does this look right?"
MOD_PAGESPEED_DIR="$MOD_PAGESPEED_DIR" \
PSOL_BINARY="$PSOL_BINARY" \
run "${configure[@]}"
if ! "$DEVEL"; then
continue_or_exit "Build nginx?"
fi
run make
if "$DEVEL"; then
run make install
status "Nginx installed with ngx_pagespeed, and set up for development."
echo "To run tests:"
echo " cd $nps_module_dir"
echo " test/run_tests.sh"
echo
echo "To rebuild after changes:"
echo " scripts/rebuild.sh"
else
continue_or_exit "Install nginx?"
run sudo make install
echo
if "$DYNAMIC_MODULE"; then
echo "Nginx installed with ngx_pagespeed support available as a"
echo "loadable module."
echo
echo "To load the ngx_pagespeed module, you'll need to add:"
echo " load_module \"modules/ngx_pagespeed.so\";"
echo "at the top of your main nginx configuration file."
else
echo "Nginx installed with ngx_pagespeed support compiled-in."
fi
echo
echo "If this is a new installation you probably need an init script to"
echo "manage starting and stopping the nginx service. See:"
echo " http://wiki.nginx.org/InitScripts"
echo
echo "You'll also need to configure ngx_pagespeed if you haven't yet:"
echo " https://developers.google.com/speed/pagespeed/module/configuration"
fi
fi
if "$DRYRUN"; then
echo_color "$YELLOW" "[this was a dry run; your system is unchanged]"
fi
}
# Start running things from a call at the end so if this script is executed
# after a partial download it doesn't do anything.
build_ngx_pagespeed "$@"
+40
View File
@@ -0,0 +1,40 @@
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
set -e
set -u
if [ $# -ne 1 ]; then
echo "Usage: $(basename $0) <url_file>" >&2
exit 1
fi
url_file=$1
if [ ! -e "$url_file" ]; then
echo "Url file '$url_file' missing!" >&2
fi
# The size names must match install/build_psol.sh in mod_pagespeed
if [ "$(uname -m)" = x86_64 ]; then
bit_size_name=x64
else
bit_size_name=ia32
fi
sed -e 's/$BIT_SIZE_NAME/'$bit_size_name'/g' $url_file
+35
View File
@@ -0,0 +1,35 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Converts pagespeed_libraries.conf from Apache-format to Nginx-format,
# supporting the canonicalize_javascript_libraries filter.
# Inspired by https://github.com/apache/incubator-pagespeed-ngx/issues/532
#
# Usage:
# scripts/pagespeed_libraries_generator.sh > pagespeed_libraries.conf
#
# Then have nginx include that configuration file and enable the filter
# canonicalize_javascript_libraries.
URL="https://github.com/apache/incubator-pagespeed-mod/raw/master/"
URL+="net/instaweb/genfiles/conf/pagespeed_libraries.conf"
curl -L -s -S "$URL" \
| grep ModPagespeedLibrary \
| while read library size hash url ; do
echo " pagespeed Library $size $hash $url;"
done
-89
View File
@@ -1,89 +0,0 @@
#!/bin/bash
#
# Copyright 2012 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author: jefftk@google.com (Jeff Kaufman)
#
# Usage:
# scripts/prepare_psol.sh /path/to/mod_pagespeed/src
#
# Creates a directory psol/ and copies headers and a few source files from a
# depot_tools (glient) checkout into psol/include. Along with creating
# binaries, this is a step in preparing psol.tar.gz for distribution.
#
set -u # check for undefined variables
set -e # exit on failed commands
if [ "$(basename "$PWD")" != "ngx_pagespeed" ] ; then
echo "$(basename $0) must be invoked from the ngx_pagespeed directory"
exit 1
fi
if [ $# -ne 1 ] ; then
echo "Usage: $(basename $0) /path/to/mod_pagespeed/src"
exit 1
fi
MOD_PAGESPEED_SRC="$1"
if [ "$(basename "$(dirname "$MOD_PAGESPEED_SRC")")/$( \
basename "$MOD_PAGESPEED_SRC")" != "mod_pagespeed/src" ] ; then
echo "Usage: $(basename $0) /path/to/mod_pagespeed/src"
exit 1
fi
if [ -e psol ] ; then
echo "A psol/ directory already exists. Move it somewhere else and rerun."
exit 1
fi
mkdir psol/
# Copy over the .h files, plus a few selected .cc and .c files.
rsync -arvz "$MOD_PAGESPEED_SRC/" "psol/include/" --prune-empty-dirs \
--exclude=".svn" \
--exclude=".git" \
--include='*.h' \
--include='*/' \
--include="apr_thread_compatible_pool.cc" \
--include="serf_url_async_fetcher.cc" \
--include="apr_mem_cache.cc" \
--include="key_value_codec.cc" \
--include="apr_memcache2.c" \
--include="loopback_route_fetcher.cc" \
--include="add_headers_fetcher.cc" \
--include="dense_hash_map" \
--include="dense_hash_set" \
--include="sparse_hash_map" \
--include="sparse_hash_set" \
--include="sparsetable" \
--exclude='*'
mkdir -p psol/lib/Debug/linux/ia32
mkdir -p psol/lib/Debug/linux/x64
mkdir -p psol/lib/Release/linux/ia32
mkdir -p psol/lib/Release/linux/x64
# Log that we did this.
SVN_REVISION="$(svn info $MOD_PAGESPEED_SRC | grep Revision | awk '{print $2}')"
SVN_TAG="$(svn info $MOD_PAGESPEED_SRC | grep URL | awk -F/ '{print $(NF-1)}')"
DATE="$(date +%F)"
echo "${DATE}: Copied from mod_pagespeed ${SVN_TAG}@r${SVN_REVISION} ($USER)" \
>> psol/include_history.txt
echo
echo "Output is in psol/include. Now put binaries in psol/lib following"
echo "https://github.com/pagespeed/ngx_pagespeed/wiki/Building-Release-Binaries"
echo "and then you can distribute PSOL."
+37
View File
@@ -0,0 +1,37 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Usage: scripts/rebuild.sh
#
# After building with "scripts/build_ngx_pagespeed.sh --devel", if you make
# changes to ngx_pagespeed you'll need to rebuild it. The underlying commands
# aren't complicated, but it's faster to work if it's automated.
set -e # exit script if any command returns an error
set -u # exit the script if any variable is uninitialized
this_dir="$(dirname $0)"
cd "$this_dir/.."
nps_dir="$PWD"
cd "$nps_dir/testing-dependencies/mod_pagespeed/devel"
make apache_debug_psol
cd "$nps_dir/testing-dependencies/nginx/"
make
make install
+25 -24
View File
@@ -1,20 +1,23 @@
// Copyright 2010 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: jmarantz@google.com (Joshua Marantz)
// Author: sligocki@google.com (Shawn Ligocki)
// Author: jefftk@google.com (Jeff Kaufman)
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// TODO(jefftk): share more of this code with apache's log_message_handler
@@ -29,7 +32,7 @@
#include "base/debug/stack_trace.h"
#include "base/logging.h"
#include "net/instaweb/public/version.h"
#include "net/instaweb/util/public/string_util.h"
#include "pagespeed/kernel/base/string_util.h"
// Make sure we don't attempt to use LOG macros here, since doing so
// would cause us to go into an infinite log loop.
@@ -38,7 +41,7 @@
namespace {
ngx_log_t* log = NULL;
ngx_log_t* ngx_log = NULL;
ngx_uint_t GetNgxLogLevel(int severity) {
switch (severity) {
@@ -78,7 +81,7 @@ bool LogMessageHandler(int severity, const char* file, int line,
message.resize(last_msg_character_index);
}
ngx_log_error(this_log_level, log, 0, "[ngx_pagespeed %s] %s",
ngx_log_error(this_log_level, ngx_log, 0, "[ngx_pagespeed %s] %s",
net_instaweb::kModPagespeedVersion,
message.c_str());
@@ -98,15 +101,13 @@ namespace net_instaweb {
namespace log_message_handler {
const int kDebugLogLevel = -2;
void Install(ngx_log_t* log_in) {
log = log_in;
ngx_log = log_in;
logging::SetLogMessageHandler(&LogMessageHandler);
// All VLOG(2) and higher will be displayed as DEBUG logs if the nginx log
// level is DEBUG.
if (log->log_level >= NGX_LOG_DEBUG) {
if (ngx_log->log_level >= NGX_LOG_DEBUG) {
logging::SetMinLogLevel(-2);
}
}
+20 -17
View File
@@ -1,20 +1,23 @@
// Copyright 2010 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: jmarantz@google.com (Joshua Marantz)
// Author: sligocki@google.com (Shawn Ligocki)
// Author: jefftk@google.com (Jeff Kaufman)
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef LOG_MESSAGE_HANDLER_H_
#define LOG_MESSAGE_HANDLER_H_
+264 -117
View File
@@ -1,48 +1,206 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: jefftk@google.com (Jeff Kaufman)
#include "ngx_pagespeed.h" // Must come first, see comments in CollectHeaders.
#include <unistd.h> //for usleep
#include "ngx_base_fetch.h"
#include "ngx_event_connection.h"
#include "ngx_list_iterator.h"
#include "ngx_pagespeed.h"
#include "net/instaweb/http/public/response_headers.h"
#include "net/instaweb/rewriter/public/rewrite_driver.h"
#include "net/instaweb/rewriter/public/rewrite_options.h"
#include "net/instaweb/rewriter/public/rewrite_stats.h"
#include "net/instaweb/util/public/google_message_handler.h"
#include "net/instaweb/util/public/message_handler.h"
#include "pagespeed/kernel/base/google_message_handler.h"
#include "pagespeed/kernel/base/message_handler.h"
#include "pagespeed/kernel/base/posix_timer.h"
#include "pagespeed/kernel/http/response_headers.h"
namespace net_instaweb {
NgxBaseFetch::NgxBaseFetch(ngx_http_request_t* r, int pipe_fd,
const char kHeadersComplete = 'H';
const char kFlush = 'F';
const char kDone = 'D';
NgxEventConnection* NgxBaseFetch::event_connection = NULL;
int NgxBaseFetch::active_base_fetches = 0;
NgxBaseFetch::NgxBaseFetch(StringPiece url,
ngx_http_request_t* r,
NgxServerContext* server_context,
const RequestContextPtr& request_ctx)
const RequestContextPtr& request_ctx,
PreserveCachingHeaders preserve_caching_headers,
NgxBaseFetchType base_fetch_type,
const RewriteOptions* options)
: AsyncFetch(request_ctx),
url_(url.data(), url.size()),
request_(r),
server_context_(server_context),
options_(options),
need_flush_(false),
done_called_(false),
last_buf_sent_(false),
pipe_fd_(pipe_fd),
references_(2) {
references_(2),
base_fetch_type_(base_fetch_type),
preserve_caching_headers_(preserve_caching_headers),
detached_(false),
suppress_(false) {
if (pthread_mutex_init(&mutex_, NULL)) CHECK(0);
PopulateRequestHeaders();
__sync_add_and_fetch(&NgxBaseFetch::active_base_fetches, 1);
}
NgxBaseFetch::~NgxBaseFetch() {
pthread_mutex_destroy(&mutex_);
__sync_add_and_fetch(&NgxBaseFetch::active_base_fetches, -1);
}
bool NgxBaseFetch::Initialize(ngx_cycle_t* cycle) {
CHECK(event_connection == NULL) << "event connection already set";
event_connection = new NgxEventConnection(ReadCallback);
return event_connection->Init(cycle);
}
void NgxBaseFetch::Terminate() {
if (event_connection != NULL) {
GoogleMessageHandler handler;
PosixTimer timer;
int64 timeout_us = Timer::kSecondUs * 30;
int64 end_us = timer.NowUs() + timeout_us;
static unsigned int sleep_microseconds = 100;
handler.Message(
kInfo,"NgxBaseFetch::Terminate rounding up %d active base fetches.",
NgxBaseFetch::active_base_fetches);
// Try to continue processing and get the active base fetch count to 0
// until the timeout expires.
// TODO(oschaaf): This needs more work.
while (NgxBaseFetch::active_base_fetches > 0 && end_us > timer.NowUs()) {
event_connection->Drain();
usleep(sleep_microseconds);
}
if (NgxBaseFetch::active_base_fetches != 0) {
handler.Message(
kWarning,"NgxBaseFetch::Terminate timed out with %d active base fetches.",
NgxBaseFetch::active_base_fetches);
}
// Close down the named pipe.
event_connection->Shutdown();
delete event_connection;
event_connection = NULL;
}
}
const char* BaseFetchTypeToCStr(NgxBaseFetchType type) {
switch(type) {
case kPageSpeedResource:
return "ps resource";
case kHtmlTransform:
return "html transform";
case kAdminPage:
return "admin page";
case kIproLookup:
return "ipro lookup";
case kPageSpeedProxy:
return "pagespeed proxy";
}
CHECK(false);
return "can't get here";
}
// TODO(oschaaf): replace the ngx_log_error with VLOGS or pass in a
// MessageHandler and use that.
void NgxBaseFetch::ReadCallback(const ps_event_data& data) {
NgxBaseFetch* base_fetch = reinterpret_cast<NgxBaseFetch*>(data.sender);
ngx_http_request_t* r = base_fetch->request();
bool detached = base_fetch->detached();
#if (NGX_DEBUG) // `type` is unused if NGX_DEBUG isn't set, needed for -Werror.
const char* type = BaseFetchTypeToCStr(base_fetch->base_fetch_type_);
#endif
int refcount = base_fetch->DecrementRefCount();
#if (NGX_DEBUG)
ngx_log_error(NGX_LOG_DEBUG, ngx_cycle->log, 0,
"pagespeed [%p] event: %c. bf:%p (%s) - refcnt:%d - det: %c", r,
data.type, base_fetch, type, refcount, detached ? 'Y': 'N');
#endif
// If we ended up destructing the base fetch, or the request context is
// detached, skip this event.
if (refcount == 0 || detached) {
return;
}
ps_request_ctx_t* ctx = ps_get_request_context(r);
// If our request context was zeroed, skip this event.
// See https://github.com/apache/incubator-pagespeed-ngx/issues/1081
if (ctx == NULL) {
// Should not happen normally, when it does this message will cause our
// system tests to fail.
ngx_log_error(NGX_LOG_WARN, ngx_cycle->log, 0,
"pagespeed [%p] skipping event: request context gone", r);
return;
}
// Normally we expect the sender to equal the active NgxBaseFetch instance.
DCHECK(data.sender == ctx->base_fetch);
// If someone changed our request context or NgxBaseFetch, skip processing.
if (data.sender != ctx->base_fetch) {
ngx_log_error(NGX_LOG_WARN, ngx_cycle->log, 0,
"pagespeed [%p] skipping event: event originating from disassociated"
" NgxBaseFetch instance.", r);
return;
}
int rc;
bool run_posted = true;
// If we are unlucky enough to have our connection finalized mid-ipro-lookup,
// we must enter a different flow. Also see ps_in_place_check_header_filter().
if ((ctx->base_fetch->base_fetch_type_ != kIproLookup)
&& r->connection->error) {
ngx_log_error(NGX_LOG_DEBUG, ngx_cycle->log, 0,
"pagespeed [%p] request already finalized %d", r, r->count);
rc = NGX_ERROR;
run_posted = false;
} else {
rc = ps_base_fetch::ps_base_fetch_handler(r);
}
#if (NGX_DEBUG)
ngx_log_error(NGX_LOG_DEBUG, ngx_cycle->log, 0,
"pagespeed [%p] ps_base_fetch_handler() returned %d for %c",
r, rc, data.type);
#endif
ngx_connection_t* c = r->connection;
ngx_http_finalize_request(r, rc);
if (run_posted) {
// See http://forum.nginx.org/read.php?2,253006,253061
ngx_http_run_posted_requests(c);
}
}
void NgxBaseFetch::Lock() {
@@ -53,58 +211,6 @@ void NgxBaseFetch::Unlock() {
pthread_mutex_unlock(&mutex_);
}
void NgxBaseFetch::PopulateRequestHeaders() {
CopyHeadersFromTable<RequestHeaders>(&request_->headers_in.headers,
request_headers());
}
void NgxBaseFetch::PopulateResponseHeaders() {
CopyHeadersFromTable<ResponseHeaders>(&request_->headers_out.headers,
response_headers());
response_headers()->set_status_code(request_->headers_out.status);
// Manually copy over the content type because it's not included in
// request_->headers_out.headers.
response_headers()->Add(
HttpAttributes::kContentType,
ngx_psol::str_to_string_piece(request_->headers_out.content_type));
// TODO(oschaaf): ComputeCaching should be called in setupforhtml()?
response_headers()->ComputeCaching();
}
template<class HeadersT>
void NgxBaseFetch::CopyHeadersFromTable(ngx_list_t* headers_from,
HeadersT* headers_to) {
// http_version is the version number of protocol; 1.1 = 1001. See
// NGX_HTTP_VERSION_* in ngx_http_request.h
headers_to->set_major_version(request_->http_version / 1000);
headers_to->set_minor_version(request_->http_version % 1000);
// Standard nginx idiom for iterating over a list. See ngx_list.h
ngx_uint_t i;
ngx_list_part_t* part = &headers_from->part;
ngx_table_elt_t* header = static_cast<ngx_table_elt_t*>(part->elts);
for (i = 0 ; /* void */; i++) {
if (i >= part->nelts) {
if (part->next == NULL) {
break;
}
part = part->next;
header = static_cast<ngx_table_elt_t*>(part->elts);
i = 0;
}
StringPiece key = ngx_psol::str_to_string_piece(header[i].key);
StringPiece value = ngx_psol::str_to_string_piece(header[i].value);
headers_to->Add(key, value);
}
}
bool NgxBaseFetch::HandleWrite(const StringPiece& sp,
MessageHandler* handler) {
Lock();
@@ -113,13 +219,22 @@ bool NgxBaseFetch::HandleWrite(const StringPiece& sp,
return true;
}
// should only be called in nginx thread
ngx_int_t NgxBaseFetch::CopyBufferToNginx(ngx_chain_t** link_ptr) {
if (done_called_ && last_buf_sent_) {
return NGX_DECLINED;
CHECK(!(done_called_ && last_buf_sent_))
<< "CopyBufferToNginx() was called after the last buffer was sent";
// there is no buffer to send
if (!done_called_ && buffer_.empty()) {
*link_ptr = NULL;
return NGX_AGAIN;
}
int rc = ngx_psol::string_piece_to_buffer_chain(
request_->pool, buffer_, link_ptr, done_called_ /* send_last_buf */);
int rc = string_piece_to_buffer_chain(request_->pool, buffer_, link_ptr,
done_called_ /* send_last_buf */,
need_flush_);
need_flush_ = false;
if (rc != NGX_OK) {
return rc;
}
@@ -129,87 +244,119 @@ ngx_int_t NgxBaseFetch::CopyBufferToNginx(ngx_chain_t** link_ptr) {
if (done_called_) {
last_buf_sent_ = true;
return NGX_OK;
}
return NGX_OK;
return NGX_AGAIN;
}
// There may also be a race condition if this is called between the last Write()
// and Done() such that we're sending an empty buffer with last_buf set, which I
// think nginx will reject.
ngx_int_t NgxBaseFetch::CollectAccumulatedWrites(ngx_chain_t** link_ptr) {
ngx_int_t rc;
Lock();
ngx_int_t rc = CopyBufferToNginx(link_ptr);
rc = CopyBufferToNginx(link_ptr);
Unlock();
if (rc == NGX_DECLINED) {
*link_ptr = NULL;
return NGX_OK;
}
return rc;
}
ngx_int_t NgxBaseFetch::CollectHeaders(ngx_http_headers_out_t* headers_out) {
Lock();
// nginx defines _FILE_OFFSET_BITS to 64, which changes the size of off_t.
// If a standard header is accidentally included before the nginx header,
// on a 32-bit system off_t will be 4 bytes and we don't assign all the
// bits of content_length_n. Sanity check that did not happen.
// This could use static_assert, but this file is not built with --std=c++11.
bool sanity_check_off_t[sizeof(off_t) == 8 ? 1 : -1] __attribute__ ((unused));
const ResponseHeaders* pagespeed_headers = response_headers();
Unlock();
return ngx_psol::copy_response_headers_to_ngx(request_, *pagespeed_headers);
if (content_length_known()) {
headers_out->content_length = NULL;
headers_out->content_length_n = content_length();
}
return copy_response_headers_to_ngx(request_, *pagespeed_headers,
preserve_caching_headers_);
}
void NgxBaseFetch::RequestCollection() {
int rc;
char c = 'A'; // What byte we write is arbitrary.
while (true) {
rc = write(pipe_fd_, &c, 1);
if (rc == 1) {
break;
} else if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
// TODO(jefftk): is this rare enough that spinning isn't a problem? Could
// we get into a case where the pipe fills up and we spin forever?
void NgxBaseFetch::RequestCollection(char type) {
if (suppress_) {
return;
}
} else {
perror("NgxBaseFetch::RequestCollection");
break;
}
// We must optimistically increment the refcount, and decrement it
// when we conclude we failed. If we only increment on a successfull write,
// there's a small chance that between writing and adding to the refcount
// both pagespeed and nginx will release their refcount -- destructing
// this NgxBaseFetch instance.
IncrementRefCount();
if (!event_connection->WriteEvent(type, this)) {
DecrementRefCount();
}
}
void NgxBaseFetch::HandleHeadersComplete() {
// If this is a 404 response we need to count it in the stats.
if (response_headers()->status_code() == HttpStatus::kNotFound) {
server_context_->rewrite_stats()->resource_404_count()->Add(1);
int status_code = response_headers()->status_code();
bool status_ok = (status_code != 0) && (status_code < 400);
if ((base_fetch_type_ != kIproLookup) || status_ok) {
// If this is a 404 response we need to count it in the stats.
if (response_headers()->status_code() == HttpStatus::kNotFound) {
server_context_->rewrite_stats()->resource_404_count()->Add(1);
}
}
RequestCollection(); // Headers available.
RequestCollection(kHeadersComplete); // Headers available.
// For the IPRO lookup, supress notification of the nginx side here.
// If we send both the headerscomplete event and the one from done, nasty
// stuff will happen if we loose the race with with the nginx side destructing
// this base fetch instance.
if (base_fetch_type_ == kIproLookup && !status_ok) {
suppress_ = true;
}
}
bool NgxBaseFetch::HandleFlush(MessageHandler* handler) {
RequestCollection(); // A new part of the response body is available.
Lock();
need_flush_ = true;
Unlock();
RequestCollection(kFlush); // A new part of the response body is available
return true;
}
void NgxBaseFetch::Release() {
DecrefAndDeleteIfUnreferenced();
int NgxBaseFetch::DecrementRefCount() {
return DecrefAndDeleteIfUnreferenced();
}
void NgxBaseFetch::DecrefAndDeleteIfUnreferenced() {
int NgxBaseFetch::IncrementRefCount() {
return __sync_add_and_fetch(&references_, 1);
}
int NgxBaseFetch::DecrefAndDeleteIfUnreferenced() {
// Creates a full memory barrier.
if (__sync_add_and_fetch(&references_, -1) == 0) {
int r = __sync_add_and_fetch(&references_, -1);
if (r == 0) {
delete this;
}
return r;
}
void NgxBaseFetch::HandleDone(bool success) {
// TODO(jefftk): it's possible that instead of locking here we can just modify
// CopyBufferToNginx to only read done_called_ once.
CHECK(!done_called_) << "Done already called!";
Lock();
done_called_ = true;
Unlock();
close(pipe_fd_); // Indicates to nginx that we're done with the rewrite.
pipe_fd_ = -1;
RequestCollection(kDone);
DecrefAndDeleteIfUnreferenced();
}
bool NgxBaseFetch::IsCachedResultValid(const ResponseHeaders& headers) {
return OptionsAwareHTTPCacheCallback::IsCacheValid(
url_, *options_, request_context(), headers);
}
} // namespace net_instaweb
+106 -44
View File
@@ -1,38 +1,54 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: jefftk@google.com (Jeff Kaufman)
//
// Collects output from pagespeed and buffers it until nginx asks for it.
// Notifies nginx via pipe to call CollectAccumulatedWrites() on flush.
// Notifies nginx via NgxEventConnection to call ReadCallback() when
// the headers are computed, when a flush should be performed, and when done.
//
// - nginx creates a base fetch and passes it to a new proxy fetch.
// - The proxy fetch manages rewriting and thread complexity, and through
// several chained steps passes rewritten html to HandleWrite().
// - Written data is buffered.
// - When Flush() is called the base fetch writes a byte to a pipe nginx is
// watching so nginx knows to call CollectAccumulatedWrites() to pick up the
// rewritten html.
// - When Done() is called the base fetch closes the pipe, which tells nginx to
// make a final call to CollectAccumulatedWrites().
// - When HandleHeadersComplete(), HandleFlush(), or HandleDone() is called by
// PSOL, events are written to NgxEventConnection which will end up being
// handled by ReadCallback() on nginx's thread.
// When applicable, request processing will be continued via a call to
// ps_base_fetch_handler().
// - ps_base_fetch_handler() will pull the header and body bytes from PSOL
// via CollectAccumulatedWrites() and write those to the module's output.
//
// This class is referred two in two places: the proxy fetch and nginx's
// request. It must stay alive until both are finished. The proxy fetch will
// call Done() to indicate this; nginx will call Release(). Once both Done()
// and Release() have been called this class will delete itself.
// This class is referred to in three places: the proxy fetch, nginx's request,
// and pending events written to the associated NgxEventConnection. It must stay
// alive until the proxy fetch and nginx request are finished, and no more
// events are pending.
// - The proxy fetch will call Done() to indicate this.
// - nginx will call Detach() when the associated request is handled
// completely (e.g. the request context is about to be destroyed).
// - ReadCallback() will call DecrementRefCount() on instances associated to
// events it handles.
//
// When the last reference is dropped, this class will delete itself.
//
// TODO(jmarantz): consider sharing the cache-invalidation infrastructure
// with ApacheFetch, using a common base class.
#ifndef NGX_BASE_FETCH_H_
#define NGX_BASE_FETCH_H_
@@ -45,26 +61,45 @@ extern "C" {
#include "ngx_pagespeed.h"
#include "ngx_event_connection.h"
#include "ngx_server_context.h"
#include "net/instaweb/http/public/async_fetch.h"
#include "net/instaweb/http/public/headers.h"
#include "net/instaweb/util/public/string.h"
#include "net/instaweb/rewriter/public/rewrite_options.h"
#include "pagespeed/kernel/base/string.h"
#include "pagespeed/kernel/http/headers.h"
namespace net_instaweb {
enum NgxBaseFetchType {
kIproLookup,
kHtmlTransform,
kPageSpeedResource,
kAdminPage,
kPageSpeedProxy
};
class NgxBaseFetch : public AsyncFetch {
public:
NgxBaseFetch(ngx_http_request_t* r, int pipe_fd,
NgxBaseFetch(StringPiece url, ngx_http_request_t* r,
NgxServerContext* server_context,
const RequestContextPtr& request_ctx);
const RequestContextPtr& request_ctx,
PreserveCachingHeaders preserve_caching_headers,
NgxBaseFetchType base_fetch_type,
const RewriteOptions* options);
virtual ~NgxBaseFetch();
// Copies the request headers out of request_->headers_in->headers.
void PopulateRequestHeaders();
// Statically initializes event_connection, require for PSOL and nginx to
// communicate.
static bool Initialize(ngx_cycle_t* cycle);
// Copies the response headers out of request_->headers_out->headers.
void PopulateResponseHeaders();
// Attempts to finish up request processing queued up in the named pipe and
// PSOL for a fixed amount of time. If time is up, a fast and rough shutdown
// is attempted.
// Statically terminates and NULLS event_connection.
static void Terminate();
static void ReadCallback(const ps_event_data& data);
// Puts a chain in link_ptr if we have any output data buffered. Returns
// NGX_OK on success, NGX_ERROR on errors. If there's no data to send, sends
@@ -82,8 +117,24 @@ class NgxBaseFetch : public AsyncFetch {
// time for resource fetches. Not called at all for proxy fetches.
ngx_int_t CollectHeaders(ngx_http_headers_out_t* headers_out);
// Called by nginx when it's done with us.
void Release();
// Called by nginx to decrement the refcount.
int DecrementRefCount();
// Called by pagespeed to increment the refcount.
int IncrementRefCount();
// Detach() is called when the nginx side releases this base fetch. It
// sets detached_ to true and decrements the refcount. We need to know
// this to be able to handle events which nginx request context has been
// released while the event was in-flight.
void Detach() { detached_ = true; DecrementRefCount(); }
bool detached() { return detached_; }
ngx_http_request_t* request() { return request_; }
NgxBaseFetchType base_fetch_type() { return base_fetch_type_; }
bool IsCachedResultValid(const ResponseHeaders& headers) override;
private:
virtual bool HandleWrite(const StringPiece& sp, MessageHandler* handler);
@@ -91,18 +142,15 @@ class NgxBaseFetch : public AsyncFetch {
virtual void HandleHeadersComplete();
virtual void HandleDone(bool success);
// Helper method for PopulateRequestHeaders and PopulateResponseHeaders.
template<class HeadersT>
void CopyHeadersFromTable(ngx_list_t* headers_from, HeadersT* headers_to);
// Indicate to nginx that we would like it to call
// CollectAccumulatedWrites().
void RequestCollection();
void RequestCollection(char type);
// Lock must be acquired first.
// Returns:
// NGX_DECLINED: nothing to send, short circuit. Buffer not allocated.
// NGX_OK, NGX_ERROR: success, failure
// NGX_ERROR: failure
// NGX_AGAIN: still has buffer to send, need to checkout link_ptr
// NGX_OK: done, HandleDone has been called
// Allocates an nginx buffer, copies our buffer_ contents into it, clears
// buffer_.
ngx_int_t CopyBufferToNginx(ngx_chain_t** link_ptr);
@@ -112,18 +160,32 @@ class NgxBaseFetch : public AsyncFetch {
// Called by Done() and Release(). Decrements our reference count, and if
// it's zero we delete ourself.
void DecrefAndDeleteIfUnreferenced();
int DecrefAndDeleteIfUnreferenced();
static NgxEventConnection* event_connection;
// Live count of NgxBaseFetch instances that are currently in use.
static int active_base_fetches;
GoogleString url_;
ngx_http_request_t* request_;
GoogleString buffer_;
NgxServerContext* server_context_;
const RewriteOptions* options_;
bool need_flush_;
bool done_called_;
bool last_buf_sent_;
int pipe_fd_;
// How many active references there are to this fetch. Starts at two,
// decremented once when Done() is called and once when Release() is called.
// decremented once when Done() is called and once when Detach() is called.
// Incremented for each event written by pagespeed for this NgxBaseFetch, and
// decremented on the nginx side for each event read for it.
int references_;
pthread_mutex_t mutex_;
NgxBaseFetchType base_fetch_type_;
PreserveCachingHeaders preserve_caching_headers_;
// Set to true just before the nginx side releases its reference
bool detached_;
bool suppress_;
DISALLOW_COPY_AND_ASSIGN(NgxBaseFetch);
};
+54
View File
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "ngx_caching_headers.h"
#include "ngx_list_iterator.h"
#include "ngx_pagespeed.h"
namespace net_instaweb {
bool NgxCachingHeaders::Lookup(const StringPiece& key,
StringPieceVector* values) {
ngx_table_elt_t* header;
NgxListIterator it(&(request_->headers_out.headers.part));
while ((header = it.Next()) != NULL) {
if (header->hash != 0 && key == str_to_string_piece(header->key)) {
// This will be called multiple times if there are multiple headers with
// this name. Each time it will append to values.
SplitStringPieceToVector(str_to_string_piece(header->value), ",", values,
true /* omit empty strings */);
}
}
if (values->size() == 0) {
// No header found with this name.
return false;
}
for (int i = 0, n = values->size(); i < n; ++i) {
TrimWhitespace(&((*values)[i]));
}
return true;
}
} // namespace net_instaweb
+63
View File
@@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef NGX_CACHING_HEADERS_H_
#define NGX_CACHING_HEADERS_H_
extern "C" {
#include <ngx_http.h>
}
#include "pagespeed/kernel/base/basictypes.h"
#include "pagespeed/kernel/http/caching_headers.h"
namespace net_instaweb {
// Based off of ApacheCachingHeaders in net/instaweb/apache/header_util.cc
// Needed so ps_header_filter can call GenerateDisabledCacheControl().
class NgxCachingHeaders : public CachingHeaders {
public:
explicit NgxCachingHeaders(ngx_http_request_t* request)
: CachingHeaders(request->headers_out.status),
request_(request) {
}
virtual bool Lookup(const StringPiece& key, StringPieceVector* values);
virtual bool IsLikelyStaticResourceType() const {
DCHECK(false); // not called in our use-case.
return false;
}
virtual bool IsCacheableResourceStatusCode() const {
DCHECK(false); // not called in our use-case.
return false;
}
private:
ngx_http_request_t* request_;
DISALLOW_COPY_AND_ASSIGN(NgxCachingHeaders);
};
} // namespace net_instaweb
#endif // NGX_CACHING_HEADERS_H_
+183
View File
@@ -0,0 +1,183 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
extern "C" {
#include <ngx_channel.h>
}
#include "ngx_event_connection.h"
#include "pagespeed/kernel/base/google_message_handler.h"
#include "pagespeed/kernel/base/message_handler.h"
namespace net_instaweb {
NgxEventConnection::NgxEventConnection(callbackPtr callback)
: event_handler_(callback) {
}
bool NgxEventConnection::Init(ngx_cycle_t* cycle) {
int file_descriptors[2];
if (pipe(file_descriptors) != 0) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "pagespeed: pipe() failed");
return false;
}
if (ngx_nonblocking(file_descriptors[0]) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
ngx_nonblocking_n "pagespeed: pipe[0] failed");
} else if (ngx_nonblocking(file_descriptors[1]) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
ngx_nonblocking_n "pagespeed: pipe[1] failed");
} else if (!CreateNgxConnection(cycle, file_descriptors[0])) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"pagespeed: failed to create connection.");
} else {
pipe_read_fd_ = file_descriptors[0];
pipe_write_fd_ = file_descriptors[1];
// Attempt to bump the pipe capacity, because running out of buffer space
// can potentially lead up to writes spinning on EAGAIN.
// See https://github.com/apache/incubator-pagespeed-ngx/issues/1380
// TODO(oschaaf): Consider implementing a queueing mechanism for retrying
// failed writes.
#ifdef F_SETPIPE_SZ
fcntl(pipe_write_fd_, F_SETPIPE_SZ, 200*1024 /* minimal amount of bytes */);
#endif
return true;
}
close(file_descriptors[0]);
close(file_descriptors[1]);
return false;
}
bool NgxEventConnection::CreateNgxConnection(ngx_cycle_t* cycle,
ngx_fd_t pipe_fd) {
// pipe_fd (the read side of the pipe will end up as c->fd on the
// underlying ngx_connection_t that gets created here)
ngx_int_t rc = ngx_add_channel_event(cycle, pipe_fd, NGX_READ_EVENT,
&NgxEventConnection::ReadEventHandler);
return rc == NGX_OK;
}
void NgxEventConnection::ReadEventHandler(ngx_event_t* ev) {
ngx_connection_t* c = static_cast<ngx_connection_t*>(ev->data);
ngx_int_t result = ngx_handle_read_event(ev, 0);
if (result != NGX_OK) {
CHECK(false) << "pagespeed: ngx_handle_read_event error: " << result;
}
if (ev->timedout) {
ev->timedout = 0;
return;
}
if (!NgxEventConnection::ReadAndNotify(c->fd)) {
// This was copied from ngx_channel_handler(): for epoll, we need to call
// ngx_del_conn(). Sadly, no documentation as to why.
if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
ngx_del_conn(c, 0);
}
ngx_close_connection(c);
ngx_del_event(ev, NGX_READ_EVENT, 0);
}
}
// Deserialize ps_event_data's from the pipe as they become available.
// Subsequently do some bookkeeping, cleanup, and error checking to keep
// the mess out of ps_base_fetch_handler.
bool NgxEventConnection::ReadAndNotify(ngx_fd_t fd) {
while (true) {
// We read only one ps_event_data at a time for now:
// We can end up recursing all the way and end up calling ourselves here.
// If that happens in the middle of looping over multiple ps_event_data's we
// have obtained with read(), the results from the next read() will make us
// process events out of order. Which can give headaches.
// Alternatively, we could maintain a queue to make sure we process in
// sequence
ps_event_data data;
ngx_int_t size = read(fd, static_cast<void*>(&data), sizeof(data));
if (size == -1) {
if (errno == EINTR) {
continue;
// TODO(oschaaf): should we worry about spinning here?
} else if (ngx_errno == EAGAIN || ngx_errno == EWOULDBLOCK) {
return true;
}
}
if (size <= 0) {
return false;
}
data.connection->event_handler_(data);
return true;
}
}
bool NgxEventConnection::WriteEvent(void* sender) {
return WriteEvent('X' /* Anything char is fine */, sender);
}
bool NgxEventConnection::WriteEvent(char type, void* sender) {
ssize_t size = 0;
ps_event_data data;
ngx_memzero(&data, sizeof(data));
data.type = type;
data.sender = sender;
data.connection = this;
while (true) {
size = write(pipe_write_fd_,
static_cast<void*>(&data), sizeof(data));
if (size == sizeof(data)) {
return true;
} else if (size == -1) {
// TODO(oschaaf): should we worry about spinning here?
if (ngx_errno == EINTR || ngx_errno == EAGAIN
|| ngx_errno == EWOULDBLOCK) {
continue;
} else {
return false;
}
} else {
CHECK(false) << "pagespeed: unexpected return value from write(): "
<< size;
}
}
CHECK(false) << "Should not get here";
return false;
}
// Reads and processes what is available in the pipe.
void NgxEventConnection::Drain() {
NgxEventConnection::ReadAndNotify(pipe_read_fd_);
}
void NgxEventConnection::Shutdown() {
close(pipe_write_fd_);
close(pipe_read_fd_);
}
} // namespace net_instaweb
+87
View File
@@ -0,0 +1,87 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
//
// NgxEventConnection implements a means to send events from other threads to
// nginx's event loop, and is implemented by a named pipe under the hood.
// A single instance is used by NgxBaseFetch, and one instance is created per
// NgxUrlAsyncFetcher when native fetching is on.
#ifndef NGX_EVENT_CONNECTION_H_
#define NGX_EVENT_CONNECTION_H_
extern "C" {
#include <ngx_http.h>
}
#include <pthread.h>
#include "pagespeed/kernel/base/string.h"
#include "pagespeed/kernel/http/headers.h"
namespace net_instaweb {
class NgxEventConnection;
// Represents a single event that can be written to or read from the pipe.
// Technically, sender is the only data we need to send. type and connection are
// included to provide a means to trace the events along with some more
// info.
typedef struct {
char type;
void* sender;
NgxEventConnection* connection;
} ps_event_data;
// Handler signature for receiving events
typedef void (*callbackPtr)(const ps_event_data&);
// Abstracts a connection to nginx through which events can be written.
class NgxEventConnection {
public:
explicit NgxEventConnection(callbackPtr handler);
// Creates the file descriptors and ngx_connection_t required for event
// messaging between pagespeed and nginx.
bool Init(ngx_cycle_t* cycle);
// Shuts down the underlying file descriptors and connection created in Init()
void Shutdown();
// Constructs a ps_event_data and writes it to the underlying named pipe.
bool WriteEvent(char type, void* sender);
// Convenience overload for clients that have a single event type.
bool WriteEvent(void* sender);
// Reads and processes what is available in the named pipe's buffer.
void Drain();
private:
static bool CreateNgxConnection(ngx_cycle_t* cycle, ngx_fd_t pipe_fd);
static void ReadEventHandler(ngx_event_t* e);
static bool ReadAndNotify(ngx_fd_t fd);
callbackPtr event_handler_;
// We own these file descriptors
ngx_fd_t pipe_write_fd_;
ngx_fd_t pipe_read_fd_;
DISALLOW_COPY_AND_ASSIGN(NgxEventConnection);
};
} // namespace net_instaweb
#endif // NGX_EVENT_CONNECTION_H_
+806 -460
View File
File diff suppressed because it is too large Load Diff
+185 -123
View File
@@ -1,151 +1,213 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: x.dinic@gmail.com (Junmin Xiong)
//
// The fetch is started by the main thread. It will fetch the remote resource
// from the specific url asynchronously.
#ifndef NET_INSTAWEB_NGX_FETCHER_H_
#define NET_INSTAWEB_NGX_FETCHER_H_
//
// PageSpeed needs some way to talk to the internet and request resources. For
// example, if it's optimizing www.example.com/index.html and it sees html with
// <img src="//images.example.com/cat.jpg"> and images.example.com is authorized
// for rewriting in the config, then it needs to fetch cat.jpg from
// images.example.com and optimize it. In apache (always) and nginx (by
// default) we use a fetcher called "serf". This works fine, but it does run
// its own event loop. To be more efficient, this is a "native" fetcher that
// uses nginx's event loop.
//
// The fetch is started by the main thread. It will fetch the remote resource
// from the specific url asynchronously.
#ifndef NET_INSTAWEB_NGX_FETCH_H_
#define NET_INSTAWEB_NGX_FETCH_H_
extern "C" {
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
typedef bool (*response_handler_pt)(ngx_connection_t* c);
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
}
#include "ngx_url_async_fetcher.h"
#include <vector>
#include "net/instaweb/util/public/basictypes.h"
#include "net/instaweb/util/public/pool.h"
#include "net/instaweb/util/public/string.h"
#include "net/instaweb/http/public/url_pollable_async_fetcher.h"
#include "net/instaweb/http/public/response_headers.h"
#include "net/instaweb/http/public/response_headers_parser.h"
#include "net/instaweb/http/public/url_async_fetcher.h"
#include "pagespeed/kernel/base/basictypes.h"
#include "pagespeed/kernel/base/pool.h"
#include "pagespeed/kernel/base/string.h"
#include "pagespeed/kernel/http/response_headers.h"
#include "pagespeed/kernel/http/response_headers_parser.h"
#include "pagespeed/kernel/thread/pthread_mutex.h"
namespace net_instaweb {
class NgxUrlAsyncFetcher;
class NgxFetch : public PoolElement<NgxFetch> {
public:
NgxFetch(const GoogleString& url,
AsyncFetch* async_fetch,
MessageHandler* message_handler,
ngx_msec_t timeout_ms,
ngx_log_t* log);
~NgxFetch();
// Start the fetch
bool Start(NgxUrlAsyncFetcher* fetcher);
// Show the completed url, for logging purpose
const char* str_url();
// This fetch task is done. Call the done of async_fetch.
// It will copy the buffer to cache.
void CallbackDone(bool success);
typedef bool (*response_handler_pt)(ngx_connection_t* c);
// Show the bytes received
size_t bytes_received();
void bytes_received_add(int64 x);
int64 fetch_start_ms();
void set_fetch_start_ms(int64 start_ms);
int64 fetch_end_ms();
void set_fetch_end_ms(int64 end_ms);
MessageHandler* message_handler();
int get_major_version() {
return static_cast<int>(status_->http_version / 1000);
}
class NgxUrlAsyncFetcher;
class NgxConnection;
int get_minor_version() {
return static_cast<int>(status_->http_version % 1000);
}
class NgxConnection : public PoolElement<NgxConnection> {
public:
NgxConnection(MessageHandler* handler, int max_keepalive_requests);
~NgxConnection();
void SetSock(u_char *sockaddr, socklen_t socklen) {
socklen_ = socklen;
ngx_memcpy(&sockaddr_, sockaddr, socklen);
}
// Close ensures that NgxConnection deletes itself at the appropriate time,
// which can be after receiving a non-keepalive response, or when the remote
// server closes the connection when the NgxConnection is pooled and idle.
void Close();
int get_status_code() {
return static_cast<int>(status_->code);
}
// Once keepalive is disabled, it can't be toggled back on.
void set_keepalive(bool k) { keepalive_ = keepalive_ && k; }
bool keepalive() { return keepalive_; }
ngx_event_t* timeout_event() {
return timeout_event_;
};
void set_timeout_event(ngx_event_t* x) {
timeout_event_ = x;
};
typedef Pool<NgxConnection> NgxConnectionPool;
private:
response_handler_pt response_handler;
// Do the initialized work and start the resolver work.
bool Init();
bool ParseUrl();
// Prepare the request and write it to remote server.
int InitRequest();
// Create the connection with remote server.
int Connect();
void set_response_handler(response_handler_pt handler) {
response_handler = handler;
}
// Only the Static functions could be used in callbacks.
static void NgxFetchResolveDone(ngx_resolver_ctx_t* ctx);
static NgxConnection* Connect(ngx_peer_connection_t* pc,
MessageHandler* handler,
int max_keepalive_requests);
static void IdleWriteHandler(ngx_event_t* ev);
static void IdleReadHandler(ngx_event_t* ev);
// Terminate will cleanup any idle connections upon shutdown.
static void Terminate();
// Write the request
static void NgxFetchWrite(ngx_event_t* wev);
static NgxConnectionPool connection_pool;
static PthreadMutex connection_pool_mutex;
// Wait for the response
static void NgxFetchRead(ngx_event_t* rev);
// Read and parse the first status line
static bool NgxFetchHandleStatusLine(ngx_connection_t* c);
// Read and parse the HTTP headers
static bool NgxFetchHandleHeader(ngx_connection_t* c);
// Read the response body
static bool NgxFetchHandleBody(ngx_connection_t* c);
// c_ is owned by NgxConnection and freed in ::Close()
ngx_connection_t* c_;
static const int64 keepalive_timeout_ms;
static const GoogleString ka_header;
// Cancel the fetch when it's timeout
static void NgxFetchTimeout(ngx_event_t* tev);
private:
int max_keepalive_requests_;
bool keepalive_;
socklen_t socklen_;
u_char sockaddr_[NGX_SOCKADDRLEN];
MessageHandler* handler_;
// Add the pagespeed User-Agent
void FixUserAgent();
void FixHost();
DISALLOW_COPY_AND_ASSIGN(NgxConnection);
};
const GoogleString str_url_;
ngx_url_t url_;
NgxUrlAsyncFetcher* fetcher_;
AsyncFetch* async_fetch_;
ResponseHeadersParser parser_;
MessageHandler* message_handler_;
size_t bytes_received_;
int64 fetch_start_ms_;
int64 fetch_end_ms_;
int64 timeout_ms_;
bool done_;
int64 content_length_;
class NgxFetch : public PoolElement<NgxFetch> {
public:
NgxFetch(const GoogleString& url,
AsyncFetch* async_fetch,
MessageHandler* message_handler,
ngx_log_t* log);
~NgxFetch();
struct sockaddr_in sin_;
ngx_log_t* log_;
ngx_buf_t* out_;
ngx_buf_t* in_;
ngx_pool_t* pool_;
ngx_http_request_t* r_;
ngx_http_status_t* status_;
ngx_event_t* timeout_event_;
ngx_connection_t* connection_;
ngx_resolver_ctx_t* resolver_ctx_;
// Start the fetch.
bool Start(NgxUrlAsyncFetcher* fetcher);
// Show the completed url, for logging purposes.
const char* str_url();
// This fetch task is done. Call Done() on the async_fetch. It will copy the
// buffer to cache.
void CallbackDone(bool success);
DISALLOW_COPY_AND_ASSIGN(NgxFetch);
};
// Show the bytes received.
size_t bytes_received();
void bytes_received_add(int64 x);
int64 fetch_start_ms();
void set_fetch_start_ms(int64 start_ms);
int64 fetch_end_ms();
void set_fetch_end_ms(int64 end_ms);
MessageHandler* message_handler();
int get_major_version() {
return static_cast<int>(status_->http_version / 1000);
}
int get_minor_version() {
return static_cast<int>(status_->http_version % 1000);
}
int get_status_code() {
return static_cast<int>(status_->code);
}
ngx_event_t* timeout_event() {
return timeout_event_;
}
void set_timeout_event(ngx_event_t* x) {
timeout_event_ = x;
}
void release_resolver() {
if (resolver_ctx_ != NULL && resolver_ctx_ != NGX_NO_RESOLVER) {
ngx_resolve_name_done(resolver_ctx_);
resolver_ctx_ = NULL;
}
}
private:
response_handler_pt response_handler;
// Do the initialized work and start the resolver work.
bool Init();
bool ParseUrl();
// Prepare the request and write it to remote server.
int InitRequest();
// Create the connection with remote server.
int Connect();
void set_response_handler(response_handler_pt handler) {
response_handler = handler;
}
// Only the Static functions could be used in callbacks.
static void ResolveDoneHandler(ngx_resolver_ctx_t* ctx);
// Write the request.
static void ConnectionWriteHandler(ngx_event_t* wev);
// Wait for the response.
static void ConnectionReadHandler(ngx_event_t* rev);
// Read and parse the first status line.
static bool HandleStatusLine(ngx_connection_t* c);
// Read and parse the HTTP headers.
static bool HandleHeader(ngx_connection_t* c);
// Read the response body.
static bool HandleBody(ngx_connection_t* c);
// Cancel the fetch when it's timeout.
static void TimeoutHandler(ngx_event_t* tev);
// Add the pagespeed User-Agent.
void FixUserAgent();
void FixHost();
const GoogleString str_url_;
ngx_url_t url_;
NgxUrlAsyncFetcher* fetcher_;
AsyncFetch* async_fetch_;
ResponseHeadersParser parser_;
MessageHandler* message_handler_;
int64 bytes_received_;
int64 fetch_start_ms_;
int64 fetch_end_ms_;
bool done_;
int64 content_length_;
bool content_length_known_;
struct sockaddr_in sin_;
ngx_log_t* log_;
ngx_buf_t* out_;
ngx_buf_t* in_;
ngx_pool_t* pool_;
ngx_http_request_t* r_;
ngx_http_status_t* status_;
ngx_event_t* timeout_event_;
NgxConnection* connection_;
ngx_resolver_ctx_t* resolver_ctx_;
DISALLOW_COPY_AND_ASSIGN(NgxFetch);
};
} // namespace net_instaweb
#endif // NET_INSTAWEB_NGX_FETCHER_H_
#endif // NET_INSTAWEB_NGX_FETCH_H_
+406
View File
@@ -0,0 +1,406 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "ngx_gzip_setter.h"
#include <ngx_conf_file.h>
namespace net_instaweb {
NgxGZipSetter g_gzip_setter;
extern "C" {
// These functions replace the setters for:
// gzip
// gzip_types
// gzip_http_version
// gzip_vary
//
// If these functions are called it means there is an explicit gzip
// configuration. The gzip configuration set by pagespeed is then rolled
// back and pagespeed will stop enabling gzip automatically.
char* ngx_gzip_redirect_conf_set_flag_slot(
ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
if (g_gzip_setter.enabled()) {
g_gzip_setter.RollBackAndDisable(cf);
}
char* ret = ngx_conf_set_flag_slot(cf, cmd, conf);
return ret;
}
char* ngx_gzip_redirect_http_types_slot(
ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
if (g_gzip_setter.enabled()) {
g_gzip_setter.RollBackAndDisable(cf);
}
char* ret = ngx_http_types_slot(cf, cmd, conf);
return ret;
}
char* ngx_gzip_redirect_conf_set_enum_slot(
ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
if (g_gzip_setter.enabled()) {
g_gzip_setter.RollBackAndDisable(cf);
}
char* ret = ngx_conf_set_enum_slot(cf, cmd, conf);
return ret;
}
char* ngx_gzip_redirect_conf_set_bitmask_slot(
ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
if (g_gzip_setter.enabled()) {
g_gzip_setter.RollBackAndDisable(cf);
}
char* ret = ngx_conf_set_bitmask_slot(cf, cmd, conf);
return ret;
}
}
NgxGZipSetter::NgxGZipSetter() : enabled_(0) { }
NgxGZipSetter::~NgxGZipSetter() { }
// Helper functions to determine signature.
bool HasLocalConfig(ngx_command_t* command) {
return (!(command->type & (NGX_DIRECT_CONF|NGX_MAIN_CONF)) &&
command->conf == NGX_HTTP_LOC_CONF_OFFSET);
}
bool IsNgxFlagCommand(ngx_command_t* command) {
return (command->set == ngx_conf_set_flag_slot &&
HasLocalConfig(command));
}
bool IsNgxHttpTypesCommand(ngx_command_t* command) {
return (command->set == ngx_http_types_slot &&
HasLocalConfig(command));
}
bool IsNgxEnumCommand(ngx_command_t* command) {
return (command->set == ngx_conf_set_enum_slot &&
HasLocalConfig(command));
}
bool IsNgxBitmaskCommand(ngx_command_t* command) {
return (command->set == ngx_conf_set_bitmask_slot &&
HasLocalConfig(command));
}
// Initialize the NgxGzipSetter.
// Find the gzip, gzip_vary, gzip_http_version and gzip_types commands in the
// gzip module. Enable if the signature of the zip command matches with what we
// trust. Also sets up redirects for the configurations. These redirect handle
// a rollback if expicit configuration is found.
// If commands are not found the method will inform the user by logging.
void NgxGZipSetter::Init(ngx_conf_t* cf) {
#if (NGX_HTTP_GZIP)
bool gzip_signature_mismatch = false;
bool other_signature_mismatch = false;
for (int m = 0; cf->cycle->modules[m] != NULL; m++) {
if (cf->cycle->modules[m]->commands != NULL) {
for (int c = 0; cf->cycle->modules[m]->commands[c].name.len; c++) {
ngx_command_t* current_command =& cf->cycle->modules[m]->commands[c];
// We look for the gzip command, and the exact signature we trust
// this means configured as an config location offset
// and a ngx_flag_t setter.
// Also see:
// ngx_conf_handler in ngx_conf_file.c
// ngx_http_gzip_filter_commands in ngx_http_gzip_filter.c
if (gzip_command_.command_ == NULL &&
STR_EQ_LITERAL(current_command->name, "gzip")) {
if (IsNgxFlagCommand(current_command)) {
current_command->set = ngx_gzip_redirect_conf_set_flag_slot;
gzip_command_.command_ = current_command;
gzip_command_.module_ = cf->cycle->modules[m];
enabled_ = 1;
} else {
ngx_conf_log_error(
NGX_LOG_WARN, cf, 0,
"pagespeed: cannot set gzip, signature mismatch");
gzip_signature_mismatch = true;
}
}
if (!gzip_http_version_command_.command_ &&
STR_EQ_LITERAL(current_command->name, "gzip_http_version")) {
if (IsNgxEnumCommand(current_command)) {
current_command->set = ngx_gzip_redirect_conf_set_enum_slot;
gzip_http_version_command_.command_ = current_command;
gzip_http_version_command_.module_ = cf->cycle->modules[m];
} else {
ngx_conf_log_error(
NGX_LOG_WARN, cf, 0,
"pagespeed: cannot set gzip_http_version, signature mismatch");
other_signature_mismatch = true;
}
}
if (!gzip_proxied_command_.command_ &&
STR_EQ_LITERAL(current_command->name, "gzip_proxied")) {
if (IsNgxBitmaskCommand(current_command)) {
current_command->set = ngx_gzip_redirect_conf_set_bitmask_slot;
gzip_proxied_command_.command_ = current_command;
gzip_proxied_command_.module_ = cf->cycle->modules[m];
} else {
ngx_conf_log_error(
NGX_LOG_WARN, cf, 0,
"pagespeed: cannot set gzip_proxied, signature mismatch");
other_signature_mismatch = true;
}
}
if (!gzip_http_types_command_.command_ &&
STR_EQ_LITERAL(current_command->name, "gzip_types")) {
if (IsNgxHttpTypesCommand(current_command)) {
current_command->set = ngx_gzip_redirect_http_types_slot;
gzip_http_types_command_.command_ = current_command;
gzip_http_types_command_.module_ = cf->cycle->modules[m];
} else {
ngx_conf_log_error(
NGX_LOG_WARN, cf, 0,
"pagespeed: cannot set gzip_types, signature mismatch");
other_signature_mismatch = true;
}
}
if (!gzip_vary_command_.command_ &&
STR_EQ_LITERAL(current_command->name, "gzip_vary")) {
if (IsNgxFlagCommand(current_command)) {
current_command->set = ngx_gzip_redirect_conf_set_flag_slot;
gzip_vary_command_.command_ = current_command;
gzip_vary_command_.module_ = cf->cycle->modules[m];
} else {
ngx_conf_log_error(
NGX_LOG_WARN, cf, 0,
"pagespeed: cannot set gzip_vary, signature mismatch");
other_signature_mismatch = true;
}
}
}
}
}
if (gzip_signature_mismatch) {
return; // Already logged error.
} else if (!enabled_) {
// Looked through all the available commands and didn't find the "gzip" one.
ngx_conf_log_error(
NGX_LOG_WARN, cf, 0, "pagespeed: cannot set gzip, command not found");
return;
} else if (other_signature_mismatch) {
return; // Already logged error.
} else if (!gzip_vary_command_.command_) {
ngx_conf_log_error(
NGX_LOG_WARN, cf, 0, "pagespeed: missing gzip_vary");
return;
} else if (!gzip_http_types_command_.command_) {
ngx_conf_log_error(
NGX_LOG_WARN, cf, 0, "pagespeed: missing gzip_types");
return;
} else if (!gzip_http_version_command_.command_) {
ngx_conf_log_error(
NGX_LOG_WARN, cf, 0, "pagespeed: missing gzip_http_version");
return;
} else if (!gzip_proxied_command_.command_) {
ngx_conf_log_error(
NGX_LOG_WARN, cf, 0, "pagespeed: missing gzip_proxied");
return;
} else {
return; // Success.
}
#else
ngx_conf_log_error(
NGX_LOG_WARN, cf, 0, "pagespeed: gzip not compiled into nginx");
return;
#endif
}
void* ngx_command_ctx::GetConfPtr(ngx_conf_t* cf) {
return GetModuleConfPtr(cf) + command_->offset;
}
char* ngx_command_ctx::GetModuleConfPtr(ngx_conf_t* cf) {
return reinterpret_cast<char*>(
ngx_http_conf_get_module_loc_conf(cf, (*(module_))));
}
void NgxGZipSetter::SetNgxConfFlag(ngx_conf_t* cf,
ngx_command_ctx* command_ctx,
ngx_flag_t value) {
ngx_flag_t* flag = reinterpret_cast<ngx_flag_t*>(command_ctx->GetConfPtr(cf));
*flag = value;
// Save the flag position for possible rollback.
ngx_flags_set_.push_back(flag);
}
void NgxGZipSetter::SetNgxConfEnum(ngx_conf_t* cf,
ngx_command_ctx* command_ctx,
ngx_uint_t value) {
ngx_uint_t* enum_to_set =
reinterpret_cast<ngx_uint_t*>(command_ctx->GetConfPtr(cf));
*enum_to_set = value;
ngx_uint_set_.push_back(enum_to_set);
}
void NgxGZipSetter::SetNgxConfBitmask(ngx_conf_t* cf,
ngx_command_ctx* command_ctx,
ngx_uint_t value) {
ngx_uint_t* enum_to_set =
reinterpret_cast<ngx_uint_t*>(command_ctx->GetConfPtr(cf));
*enum_to_set = value;
ngx_uint_set_.push_back(enum_to_set);
}
// These are the content types we want to compress.
ngx_str_t gzip_http_types[] = {
ngx_string("application/ecmascript"),
ngx_string("application/javascript"),
ngx_string("application/json"),
ngx_string("application/pdf"),
ngx_string("application/postscript"),
ngx_string("application/x-javascript"),
ngx_string("image/svg+xml"),
ngx_string("text/css"),
ngx_string("text/csv"),
// ngx_string("text/html"), // This is the default implied value.
ngx_string("text/javascript"),
ngx_string("text/plain"),
ngx_string("text/xml"),
ngx_null_string // Indicates end of array.
};
gzs_enable_result NgxGZipSetter::SetGZipForLocation(ngx_conf_t* cf,
bool value) {
if (!enabled_) {
return kEnableGZipNotEnabled;
}
if (gzip_command_.command_) {
SetNgxConfFlag(cf, &gzip_command_, value);
}
return kEnableGZipOk;
}
void NgxGZipSetter::EnableGZipForLocation(ngx_conf_t* cf) {
if (!enabled_) {
return;
}
// When we get called twice for the same location{}, we ignore the second call
// to prevent adding duplicate gzip http types and so on.
ngx_flag_t* flag =
reinterpret_cast<ngx_flag_t*>(gzip_command_.GetConfPtr(cf));
if (*flag == 1) {
return;
}
SetGZipForLocation(cf, true);
if (gzip_vary_command_.command_) {
SetNgxConfFlag(cf, &gzip_vary_command_, 1);
}
if (gzip_http_version_command_.command_) {
SetNgxConfEnum(cf, &gzip_http_version_command_, NGX_HTTP_VERSION_10);
}
if (gzip_proxied_command_.command_) {
SetNgxConfBitmask(
cf, &gzip_proxied_command_, NGX_HTTP_GZIP_PROXIED_ANY);
}
// This is actually the most prone to future API changes, because gzip_types
// is not a simple type like ngx_flag_t. The signature check should be enough
// to prevent problems.
AddGZipHTTPTypes(cf);
return;
}
void NgxGZipSetter::AddGZipHTTPTypes(ngx_conf_t* cf) {
if (gzip_http_types_command_.command_) {
// Following should not happen, but if it does return gracefully.
if (cf->args->nalloc < 2) {
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"pagespeed: unexpected small cf->args in gzip_types");
return;
}
ngx_command_t* command = gzip_http_types_command_.command_;
char* gzip_conf = reinterpret_cast<char* >(
gzip_http_types_command_.GetModuleConfPtr(cf));
// Backup the old settings.
ngx_str_t old_elt0 = reinterpret_cast<ngx_str_t*>(cf->args->elts)[0];
ngx_str_t old_elt1 = reinterpret_cast<ngx_str_t*>(cf->args->elts)[1];
ngx_uint_t old_nelts = cf->args->nelts;
// Setup first arg.
ngx_str_t gzip_types_string = ngx_string("gzip_types");
reinterpret_cast<ngx_str_t*>(cf->args->elts)[0] = gzip_types_string;
cf->args->nelts = 2;
ngx_str_t* http_types = gzip_http_types;
while (http_types->data) {
ngx_str_t d;
// We allocate the http type on the configuration pool and actually
// leak this if we rollback. This does not seem to be a big problem,
// because nginx also allocates tokens in ngx_conf_file.c and does not
// free them. This way they can be used safely by configurations.
// We must use a copy of gzip_http_types array here because nginx will
// manipulate the values.
// TODO(kspoelstra): better would be to allocate once on init and not
// every time we enable gzip. This needs further investigation, sharing
// tokens might be problematic.
// For now I think it is not a large problem. This might add up in case
// of a large multi server/location config with a lot of "pagespeed on"
// directives.
// Estimates are 300-400KB for 1000 times "pagespeed on".
d.data = reinterpret_cast<u_char*>(
ngx_pnalloc(cf->pool, http_types->len + 1));
snprintf(reinterpret_cast<char*>(d.data), http_types->len + 1, "%s",
reinterpret_cast<const char*>(http_types->data));
d.len = http_types->len;
reinterpret_cast<ngx_str_t*>(cf->args->elts)[1] = d;
// Call the original setter.
ngx_http_types_slot(cf, command, gzip_conf);
http_types++;
}
// Restore args.
cf->args->nelts = old_nelts;
reinterpret_cast<ngx_str_t*>(cf->args->elts)[1] = old_elt1;
reinterpret_cast<ngx_str_t*>(cf->args->elts)[0] = old_elt0;
// Backup configuration location for rollback.
ngx_httptypes_set_.push_back(gzip_conf + command->offset);
}
}
void NgxGZipSetter::RollBackAndDisable(ngx_conf_t* cf) {
ngx_conf_log_error(NGX_LOG_INFO, cf, 0,
"pagespeed: rollback gzip, explicit configuration");
for (std::vector<ngx_flag_t*>::iterator i = ngx_flags_set_.begin();
i != ngx_flags_set_.end(); ++i) {
*(*i)=NGX_CONF_UNSET;
}
for (std::vector<ngx_uint_t*>::iterator i = ngx_uint_set_.begin();
i != ngx_uint_set_.end(); ++i) {
*(*i)=NGX_CONF_UNSET_UINT;
}
for (std::vector<void*>::iterator i = ngx_httptypes_set_.begin();
i != ngx_httptypes_set_.end(); ++i) {
ngx_array_t** type_array = reinterpret_cast<ngx_array_t**>(*i);
ngx_array_destroy(*type_array);
*type_array = NULL;
}
enabled_ = 0;
}
} // namespace net_instaweb
+127
View File
@@ -0,0 +1,127 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* NgxGZipSetter sets up gzip for pagespeed
* with the following configuration:
* gzip on;
* gzip_vary on;
* gzip_types application/ecmascript;
* gzip_types application/javascript;
* gzip_types application/json;
* gzip_types application/pdf;
* gzip_types application/postscript;
* gzip_types application/x-javascript;
* gzip_types image/svg+xml;
* gzip_types text/css;
* gzip_types text/csv;
* gzip_types text/javascript;
* gzip_types text/plain;
* gzip_types text/xml;
* gzip_http_version 1.0;
*
* If there is an explicit gzip configuration in the nginx.conf
* pagespeed will rollback the set configuration and let the
* user decide what the configuration will be.
*
* It manipulates the configuration by manipulating ngx_flag_t
* and ngx_uint_t settings directly and using the nginx setter for
* gzip_http_types.
* This is probably a safe way to do it. If this mechanism
* changes all non nginx module setup & configuration will
* fail.
*/
#ifndef NGX_GZIP_SETTER_H_
#define NGX_GZIP_SETTER_H_
extern "C" {
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
}
#include <vector>
#include "ngx_pagespeed.h"
#include "pagespeed/kernel/base/basictypes.h"
namespace net_instaweb {
// We need this class because configuration for gzip is in different modules, so
// just saving the command will not work.
class ngx_command_ctx {
public:
ngx_command_ctx() : command_(NULL), module_(NULL) { }
void* GetConfPtr(ngx_conf_t* cf);
char* GetModuleConfPtr(ngx_conf_t* cf);
ngx_command_t* command_;
ngx_module_t* module_;
};
enum gzs_enable_result {
kEnableGZipOk,
kEnableGZipPartial,
kEnableGZipNotEnabled
};
class NgxGZipSetter {
std::vector<ngx_flag_t*> ngx_flags_set_;
std::vector<ngx_uint_t*> ngx_uint_set_;
std::vector<void*> ngx_httptypes_set_;
ngx_command_ctx gzip_command_;
ngx_command_ctx gzip_http_types_command_;
ngx_command_ctx gzip_proxied_command_;
ngx_command_ctx gzip_vary_command_;
ngx_command_ctx gzip_http_version_command_;
bool enabled_;
public:
NgxGZipSetter();
~NgxGZipSetter();
void Init(ngx_conf_t* cf);
void SetNgxConfFlag(ngx_conf_t* cf,
ngx_command_ctx* command_ctx,
ngx_flag_t value);
void SetNgxConfEnum(ngx_conf_t* cf,
ngx_command_ctx* command_ctx,
ngx_uint_t value);
void SetNgxConfBitmask(ngx_conf_t* cf,
ngx_command_ctx* command_ctx,
ngx_uint_t value);
void EnableGZipForLocation(ngx_conf_t* cf);
gzs_enable_result SetGZipForLocation(ngx_conf_t* cf, bool value);
void AddGZipHTTPTypes(ngx_conf_t* cf);
void RollBackAndDisable(ngx_conf_t* cf);
bool enabled() { return enabled_; }
private:
DISALLOW_COPY_AND_ASSIGN(NgxGZipSetter);
};
extern NgxGZipSetter g_gzip_setter;
} // namespace net_instaweb
#endif // NGX_GZIP_SETTER_H_
+42
View File
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "ngx_list_iterator.h"
namespace net_instaweb {
NgxListIterator::NgxListIterator(ngx_list_part_t* part) :
part_(part),
index_within_part_(0) {}
ngx_table_elt_t* NgxListIterator::Next() {
if (index_within_part_ >= part_->nelts) {
if (part_->next == NULL) {
return NULL;
}
part_ = part_->next;
index_within_part_ = 0;
}
ngx_table_elt_t* elts = static_cast<ngx_table_elt_t*>(part_->elts);
return &elts[index_within_part_++]; // Intentional post-increment.
}
} // namespace net_instaweb
+53
View File
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
//
// Simplifies iteration over nginx lists.
//
//
#ifndef NGX_LIST_ITERATOR_H_
#define NGX_LIST_ITERATOR_H_
extern "C" {
#include <ngx_http.h>
}
#include "base/basictypes.h"
namespace net_instaweb {
class NgxListIterator {
public:
explicit NgxListIterator(ngx_list_part_t* part);
// Return the next element of the list if there is one, NULL otherwise.
ngx_table_elt_t* Next();
private:
ngx_list_part_t* part_;
ngx_uint_t index_within_part_;
DISALLOW_COPY_AND_ASSIGN(NgxListIterator);
};
} // namespace net_instaweb
#endif // NGX_LIST_ITERATOR_H_
+40 -80
View File
@@ -1,30 +1,36 @@
// Copyright 2013 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: oschaaf@gmail.com (Otto van der Schaaf)
#include "ngx_message_handler.h"
#include <signal.h>
#include "apr_time.h"
#include "net/instaweb/util/public/abstract_mutex.h"
#include "net/instaweb/util/public/debug.h"
#include "net/instaweb/util/public/shared_circular_buffer.h"
#include "net/instaweb/util/public/string_util.h"
#include "net/instaweb/public/version.h"
#include "pagespeed/kernel/base/abstract_mutex.h"
#include "pagespeed/kernel/base/debug.h"
#include "pagespeed/kernel/base/posix_timer.h"
#include "pagespeed/kernel/base/string_util.h"
#include "pagespeed/kernel/base/time_util.h"
#include "pagespeed/kernel/sharedmem/shared_circular_buffer.h"
namespace {
@@ -56,11 +62,9 @@ extern "C" {
namespace net_instaweb {
NgxMessageHandler::NgxMessageHandler(AbstractMutex* mutex)
: mutex_(mutex),
buffer_(NULL),
NgxMessageHandler::NgxMessageHandler(Timer* timer, AbstractMutex* mutex)
: SystemMessageHandler(timer, mutex),
log_(NULL) {
SetPidString(static_cast<int64>(getpid()));
}
// Installs a signal handler for common crash signals, that tries to print
@@ -73,14 +77,6 @@ void NgxMessageHandler::InstallCrashHandler(ngx_log_t* log) {
signal(SIGSEGV, signal_handler);
}
bool NgxMessageHandler::Dump(Writer* writer) {
// Can't dump before SharedCircularBuffer is set up.
if (buffer_ == NULL) {
return false;
}
return buffer_->Dump(writer, &handler_);
}
ngx_uint_t NgxMessageHandler::GetNgxLogLevel(MessageType type) {
switch (type) {
case kInfo:
@@ -98,65 +94,29 @@ ngx_uint_t NgxMessageHandler::GetNgxLogLevel(MessageType type) {
return NGX_LOG_ALERT;
}
void NgxMessageHandler::set_buffer(SharedCircularBuffer* buff) {
ScopedMutex lock(mutex_.get());
buffer_ = buff;
}
void NgxMessageHandler::MessageVImpl(MessageType type, const char* msg,
va_list args) {
ngx_uint_t log_level = GetNgxLogLevel(type);
GoogleString formatted_message = Format(msg, args);
void NgxMessageHandler::MessageSImpl(MessageType type,
const GoogleString& message) {
if (log_ != NULL) {
ngx_uint_t log_level = GetNgxLogLevel(type);
ngx_log_error(log_level, log_, 0/*ngx_err_t*/, "[%s %s] %s",
kModuleName, kModPagespeedVersion, formatted_message.c_str());
kModuleName, kModPagespeedVersion, message.c_str());
} else {
GoogleMessageHandler::MessageVImpl(type, msg, args);
}
// Prepare a log message for the SharedCircularBuffer only.
// Prepend time and severity to message.
// Format is [time] [severity] [pid] message.
GoogleString message;
char time_buffer[APR_CTIME_LEN + 1];
const char* time = time_buffer;
apr_status_t status = apr_ctime(time_buffer, apr_time_now());
if (status != APR_SUCCESS) {
time = "?";
}
StrAppend(&message, "[", time, "] ",
"[", MessageTypeToString(type), "] ");
StrAppend(&message, pid_string_, " ", formatted_message, "\n");
{
ScopedMutex lock(mutex_.get());
if (buffer_ != NULL) {
buffer_->Write(message);
}
GoogleMessageHandler::MessageSImpl(type, message);
}
AddMessageToBuffer(type, message);
}
void NgxMessageHandler::FileMessageVImpl(MessageType type, const char* file,
int line, const char* msg,
va_list args) {
ngx_uint_t log_level = GetNgxLogLevel(type);
GoogleString formatted_message = Format(msg, args);
void NgxMessageHandler::FileMessageSImpl(
MessageType type, const char* file, int line, const GoogleString& message) {
if (log_ != NULL) {
ngx_uint_t log_level = GetNgxLogLevel(type);
ngx_log_error(log_level, log_, 0/*ngx_err_t*/, "[%s %s] %s:%d:%s",
kModuleName, kModPagespeedVersion, file, line,
formatted_message.c_str());
message.c_str());
} else {
GoogleMessageHandler::FileMessageVImpl(type, file, line, msg, args);
GoogleMessageHandler::FileMessageSImpl(type, file, line, message);
}
}
// TODO(sligocki): It'd be nice not to do so much string copying.
GoogleString NgxMessageHandler::Format(const char* msg, va_list args) {
GoogleString buffer;
// Ignore the name of this routine: it formats with vsnprintf.
// See base/stringprintf.cc.
StringAppendV(&buffer, msg, args);
return buffer;
AddMessageToBuffer(type, file, line, message);
}
} // namespace net_instaweb
+35 -46
View File
@@ -1,82 +1,71 @@
// Copyright 2013 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: oschaaf@gmail.com (Otto van der Schaaf)
#ifndef NGX_MESSAGE_HANDLER_H_
#define NGX_MESSAGE_HANDLER_H_
extern "C" {
#include <ngx_auto_config.h>
#if (NGX_THREADS)
#include <ngx_thread.h>
#endif
#include <ngx_core.h>
#include <ngx_log.h>
}
#include <cstdarg>
#include "net/instaweb/util/public/basictypes.h"
#include "net/instaweb/util/public/google_message_handler.h"
#include "net/instaweb/util/public/message_handler.h"
#include "net/instaweb/util/public/scoped_ptr.h"
#include "net/instaweb/util/public/string.h"
#include "net/instaweb/util/public/string_util.h"
#include "pagespeed/kernel/base/basictypes.h"
#include "pagespeed/kernel/base/message_handler.h"
#include "pagespeed/kernel/base/string.h"
#include "pagespeed/kernel/base/string_util.h"
#include "pagespeed/system/system_message_handler.h"
namespace net_instaweb {
class AbstractMutex;
class SharedCircularBuffer;
class Timer;
class Writer;
// Implementation of a message handler that uses ngx_log_error()
// logging to emit messages, with a fallback to GoogleMessageHandler
class NgxMessageHandler : public GoogleMessageHandler {
class NgxMessageHandler : public SystemMessageHandler {
public:
explicit NgxMessageHandler(AbstractMutex* mutex);
explicit NgxMessageHandler(Timer* timer, AbstractMutex* mutex);
// Installs a signal handler for common crash signals that tries to print
// out a backtrace.
static void InstallCrashHandler(ngx_log_t* log);
// When NgxRewriteDriver instantiates the NgxMessageHandlers, the
// SharedCircularBuffer and ngx_log_t are not available yet. These
// will later be set in RootInit/Childinit
// Messages logged before that will be passed on to handler_;
void set_buffer(SharedCircularBuffer* buff);
void set_log(ngx_log_t* log) { log_ = log; }
void SetPidString(const int64 pid) {
pid_string_ = StrCat("[", Integer64ToString(pid), "]");
}
// Dump contents of SharedCircularBuffer.
bool Dump(Writer* writer);
ngx_log_t* log() { return log_; }
protected:
virtual void MessageVImpl(MessageType type, const char* msg, va_list args);
virtual void MessageSImpl(MessageType type, const GoogleString& message);
virtual void FileMessageVImpl(MessageType type, const char* filename,
int line, const char* msg, va_list args);
virtual void FileMessageSImpl(MessageType type, const char* file,
int line, const GoogleString& message);
private:
ngx_uint_t GetNgxLogLevel(MessageType type);
GoogleString Format(const char* msg, va_list args);
scoped_ptr<AbstractMutex> mutex_;
GoogleString pid_string_;
// handler_ is used as a fallback when we can not use ngx_log_errort
// It's also used when calling Dump on the internal SharedCircularBuffer
GoogleMessageHandler handler_;
SharedCircularBuffer* buffer_;
ngx_log_t* log_;
DISALLOW_COPY_AND_ASSIGN(NgxMessageHandler);
+1965 -1448
View File
File diff suppressed because it is too large Load Diff
+78 -35
View File
@@ -1,20 +1,23 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: jefftk@google.com (Jeff Kaufman)
#ifndef NGX_PAGESPEED_H_
#define NGX_PAGESPEED_H_
@@ -34,8 +37,8 @@ extern "C" {
}
#include "base/logging.h"
#include "net/instaweb/http/public/response_headers.h"
#include "net/instaweb/util/public/string_util.h"
#include "pagespeed/kernel/base/string_util.h"
#include "pagespeed/kernel/http/response_headers.h"
namespace net_instaweb {
@@ -43,17 +46,16 @@ class GzipInflater;
class NgxBaseFetch;
class ProxyFetch;
class RewriteDriver;
} // namespace net_instaweb
namespace ngx_psol {
class RequestHeaders;
class ResponseHeaders;
class InPlaceResourceRecorder;
// Allocate chain links and buffers from the supplied pool, and copy over the
// data from the string piece. If the string piece is empty, return
// NGX_DECLINED immediately unless send_last_buf.
ngx_int_t string_piece_to_buffer_chain(
ngx_pool_t* pool, StringPiece sp,
ngx_chain_t** link_ptr, bool send_last_buf);
ngx_chain_t** link_ptr, bool send_last_buf, bool send_flush);
StringPiece str_to_string_piece(ngx_str_t s);
@@ -75,24 +77,65 @@ StringPiece str_to_string_piece(ngx_str_t s);
// Allocate memory out of the pool for the string piece, and copy the contents
// over. Returns NULL if we can't get memory.
char* string_piece_to_pool_string(ngx_pool_t* pool, StringPiece sp);
ngx_int_t copy_response_headers_to_ngx(
ngx_http_request_t* r,
const net_instaweb::ResponseHeaders& pagespeed_headers);
enum PreserveCachingHeaders {
kPreserveAllCachingHeaders, // Cache-Control, ETag, Last-Modified, etc
kPreserveOnlyCacheControl, // Only Cache-Control.
kDontPreserveHeaders,
};
typedef struct {
net_instaweb::ProxyFetch* proxy_fetch;
net_instaweb::NgxBaseFetch* base_fetch;
net_instaweb::RewriteDriver* driver;
bool data_received;
int pipe_fd;
ngx_connection_t* pagespeed_connection;
NgxBaseFetch* base_fetch;
ngx_http_request_t* r;
bool is_resource_fetch;
bool sent_headers;
bool write_pending;
net_instaweb::GzipInflater* inflater_;
bool html_rewrite;
bool in_place;
PreserveCachingHeaders preserve_caching_headers;
// for html rewrite
ProxyFetch* proxy_fetch;
GzipInflater* inflater_;
// for in place resource
RewriteDriver* driver;
InPlaceResourceRecorder* recorder;
ResponseHeaders* ipro_response_headers;
// We need to remember the URL here as well since we may modify what NGX
// gets by stripping our special query params and honoring X-Forwarded-Proto.
GoogleString url_string;
// We need to remember if the upstream had headers_out->location set, because
// we should mirror that when we write it back. nginx may absolutify
// Location: headers that start with '/' without regarding X-Forwarded-Proto.
bool location_field_set;
bool psol_vary_accept_only;
bool follow_flushes;
} ps_request_ctx_t;
} // namespace ngx_psol
ps_request_ctx_t* ps_get_request_context(ngx_http_request_t* r);
void copy_request_headers_from_ngx(const ngx_http_request_t* r,
RequestHeaders* headers);
void copy_response_headers_from_ngx(const ngx_http_request_t* r,
ResponseHeaders* headers);
ngx_int_t copy_response_headers_to_ngx(
ngx_http_request_t* r,
const ResponseHeaders& pagespeed_headers,
PreserveCachingHeaders preserve_caching_headers);
StringPiece ps_determine_host(ngx_http_request_t* r);
namespace ps_base_fetch {
ngx_int_t ps_base_fetch_handler(ngx_http_request_t* r);
} // namespace ps_base_fetch
} // namespace net_instaweb
#endif // NGX_PAGESPEED_H_
-82
View File
@@ -1,82 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ngx_request_context.h"
extern "C" {
#include <ngx_http.h>
}
#include "ngx_pagespeed.h"
#include "base/logging.h"
#include "net/instaweb/http/public/meta_data.h"
namespace net_instaweb {
NgxRequestContext::NgxRequestContext(AbstractMutex* logging_mutex,
Timer* timer,
ngx_http_request_t* r)
: RequestContext(logging_mutex, timer),
local_port_(-1) {
// Note that at the time we create a RequestContext we have full
// access to the nginx internal request structure. However,
// due to Cloning and (I believe) Detaching, we can initiate fetches after
// http_http_request_t* has been retired. So deep-copy the bits we need
// at the time we create our RequestContext.
// Save our own IP as well, LoopbackRouteFetcher will need it.
// Based on ngx_http_variable_server_port.
bool port_set = false;
#if (NGX_HAVE_INET6)
if (r->connection->local_sockaddr->sa_family == AF_INET6) {
local_port_ = ntohs(reinterpret_cast<struct sockaddr_in6*>(
r->connection->local_sockaddr)->sin6_port);
port_set = true;
}
#endif
if (!port_set) {
local_port_ = ntohs(reinterpret_cast<struct sockaddr_in*>(
r->connection->local_sockaddr)->sin_port);
}
ngx_str_t s;
u_char addr[NGX_SOCKADDR_STRLEN];
s.len = NGX_SOCKADDR_STRLEN;
s.data = addr;
ngx_int_t rc = ngx_connection_local_sockaddr(r->connection, &s, 0);
if (rc != NGX_OK) {
s.len = 0;
}
local_ip_ = ngx_psol::str_to_string_piece(s).as_string();
}
NgxRequestContext::~NgxRequestContext() {
}
NgxRequestContext* NgxRequestContext::DynamicCast(RequestContext* rc) {
if (rc == NULL) {
return NULL;
}
NgxRequestContext* out = dynamic_cast<NgxRequestContext*>(rc);
DCHECK(out != NULL) << "Invalid request conversion. Do not rely on RTTI for "
<< "functional behavior. Ngx handling flows must use "
<< "NgxRequestContexts.";
return out;
}
} // namespace net_instaweb
-64
View File
@@ -1,64 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Author: oschaaf@google.com (Otto van der Schaaf)
//
// I tried to keep this as close to ApacheRequestContext as possible.
// Captures the NGINX request details in our request context, including
// the port (used for loopback fetches).
#ifndef NGX_REQUEST_CONTEXT_H_
#define NGX_REQUEST_CONTEXT_H_
#include "ngx_pagespeed.h"
#include "net/instaweb/http/public/request_context.h"
#include "net/instaweb/util/public/basictypes.h"
#include "net/instaweb/util/public/string.h"
#include "net/instaweb/util/public/string_util.h"
namespace net_instaweb {
class AbstractMutex;
class Timer;
class NgxRequestContext : public RequestContext {
public:
NgxRequestContext(AbstractMutex* logging_mutex,
Timer* timer,
ngx_http_request_t* ps_request_context);
// Returns rc as an NgxRequestContext* if it is one and CHECK
// fails if it is not. Returns NULL if rc is NULL.
static NgxRequestContext* DynamicCast(RequestContext* rc);
int local_port() const { return local_port_; }
const GoogleString& local_ip() const { return local_ip_; }
protected:
virtual ~NgxRequestContext();
private:
int local_port_;
GoogleString local_ip_;
DISALLOW_COPY_AND_ASSIGN(NgxRequestContext);
};
} // namespace net_instaweb
#endif // NGX_REQUEST_CONTEXT_H_
+144 -246
View File
@@ -1,20 +1,23 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: jefftk@google.com (Jeff Kaufman)
#include "ngx_rewrite_driver_factory.h"
@@ -24,32 +27,32 @@
#include "ngx_message_handler.h"
#include "ngx_rewrite_options.h"
#include "ngx_server_context.h"
#include "ngx_thread_system.h"
#include "ngx_url_async_fetcher.h"
#include "pthread_shared_mem.h"
#include "net/instaweb/apache/serf_url_async_fetcher.h"
#include "net/instaweb/http/public/content_type.h"
#include "net/instaweb/http/public/fake_url_async_fetcher.h"
#include "net/instaweb/http/public/rate_controller.h"
#include "net/instaweb/http/public/rate_controlling_url_async_fetcher.h"
#include "net/instaweb/http/public/wget_url_fetcher.h"
#include "net/instaweb/rewriter/public/rewrite_driver.h"
#include "net/instaweb/rewriter/public/rewrite_driver_factory.h"
#include "net/instaweb/rewriter/public/server_context.h"
#include "net/instaweb/rewriter/public/static_asset_manager.h"
#include "net/instaweb/system/public/system_caches.h"
#include "net/instaweb/system/public/system_rewrite_options.h"
#include "net/instaweb/util/public/google_message_handler.h"
#include "net/instaweb/util/public/null_shared_mem.h"
#include "net/instaweb/util/public/property_cache.h"
#include "net/instaweb/util/public/scheduler_thread.h"
#include "net/instaweb/util/public/posix_timer.h"
#include "net/instaweb/util/public/shared_circular_buffer.h"
#include "net/instaweb/util/public/shared_mem_statistics.h"
#include "net/instaweb/util/public/slow_worker.h"
#include "net/instaweb/util/public/stdio_file_system.h"
#include "net/instaweb/util/public/string.h"
#include "net/instaweb/util/public/string_util.h"
#include "net/instaweb/util/public/thread_system.h"
#include "pagespeed/kernel/base/google_message_handler.h"
#include "pagespeed/kernel/base/null_shared_mem.h"
#include "pagespeed/kernel/base/posix_timer.h"
#include "pagespeed/kernel/base/stdio_file_system.h"
#include "pagespeed/kernel/base/string.h"
#include "pagespeed/kernel/base/string_util.h"
#include "pagespeed/kernel/base/thread_system.h"
#include "pagespeed/kernel/http/content_type.h"
#include "pagespeed/kernel/sharedmem/shared_circular_buffer.h"
#include "pagespeed/kernel/sharedmem/shared_mem_statistics.h"
#include "pagespeed/kernel/thread/pthread_shared_mem.h"
#include "pagespeed/kernel/thread/scheduler_thread.h"
#include "pagespeed/kernel/thread/slow_worker.h"
#include "pagespeed/system/in_place_resource_recorder.h"
#include "pagespeed/system/serf_url_async_fetcher.h"
#include "pagespeed/system/system_caches.h"
#include "pagespeed/system/system_rewrite_options.h"
namespace net_instaweb {
@@ -62,36 +65,29 @@ class UrlAsyncFetcher;
class UrlFetcher;
class Writer;
const char NgxRewriteDriverFactory::kStaticAssetPrefix[] =
"/ngx_pagespeed_static/";
namespace {
const char kShutdownCount[] = "child_shutdown_count";
} // namespace
class SharedCircularBuffer;
NgxRewriteDriverFactory::NgxRewriteDriverFactory(
NgxThreadSystem* ngx_thread_system)
: SystemRewriteDriverFactory(ngx_thread_system),
ngx_thread_system_(ngx_thread_system),
// TODO(oschaaf): mod_pagespeed ifdefs this:
shared_mem_runtime_(new ngx::PthreadSharedMem()),
main_conf_(NULL),
const ProcessContext& process_context,
SystemThreadSystem* system_thread_system, StringPiece hostname, int port)
: SystemRewriteDriverFactory(process_context, system_thread_system,
NULL /* default shared memory runtime */, hostname, port),
threads_started_(false),
use_per_vhost_statistics_(false),
is_root_process_(true),
ngx_message_handler_(new NgxMessageHandler(thread_system()->NewMutex())),
ngx_message_handler_(
new NgxMessageHandler(timer(), thread_system()->NewMutex())),
ngx_html_parse_message_handler_(
new NgxMessageHandler(thread_system()->NewMutex())),
install_crash_handler_(false),
message_buffer_size_(0),
shared_circular_buffer_(NULL),
statistics_frozen_(false),
ngx_url_async_fetcher_(NULL),
new NgxMessageHandler(timer(), thread_system()->NewMutex())),
log_(NULL),
resolver_timeout_(NGX_CONF_UNSET_MSEC),
use_native_fetcher_(false) {
use_native_fetcher_(false),
// 100 Aligns to nginx's server-side default.
native_fetcher_max_keepalive_requests_(100),
ngx_shared_circular_buffer_(NULL),
hostname_(hostname.as_string()),
port_(port),
process_script_variables_mode_(ProcessScriptVariablesMode::kOff),
process_script_variables_set_(false),
shut_down_(false) {
InitializeDefaultOptions();
default_options()->set_beacon_url("/ngx_pagespeed_beacon");
SystemRewriteOptions* system_options = dynamic_cast<SystemRewriteOptions*>(
@@ -100,61 +96,34 @@ NgxRewriteDriverFactory::NgxRewriteDriverFactory(
system_options->set_avoid_renaming_introspective_javascript(true);
set_message_handler(ngx_message_handler_);
set_html_parse_message_handler(ngx_html_parse_message_handler_);
// see https://code.google.com/p/modpagespeed/issues/detail?id=672
int thread_limit = 1;
caches_.reset(
new SystemCaches(this, shared_mem_runtime_.get(), thread_limit));
}
NgxRewriteDriverFactory::~NgxRewriteDriverFactory() {
ShutDown();
CHECK(uninitialized_server_contexts_.empty() || is_root_process_);
ngx_shared_circular_buffer_ = NULL;
STLDeleteElements(&uninitialized_server_contexts_);
shared_mem_statistics_.reset(NULL);
}
Hasher* NgxRewriteDriverFactory::NewHasher() {
return new MD5Hasher;
}
UrlFetcher* NgxRewriteDriverFactory::DefaultUrlFetcher() {
CHECK(false) << "Nothing should still be using DefaultUrlFetcher()";
return NULL;
}
UrlAsyncFetcher* NgxRewriteDriverFactory::DefaultAsyncUrlFetcher() {
const char* fetcher_proxy = "";
if (main_conf_ != NULL) {
fetcher_proxy = main_conf_->fetcher_proxy().c_str();
}
UrlAsyncFetcher* NgxRewriteDriverFactory::AllocateFetcher(
SystemRewriteOptions* config) {
if (use_native_fetcher_) {
net_instaweb::NgxUrlAsyncFetcher* fetcher =
new net_instaweb::NgxUrlAsyncFetcher(
fetcher_proxy,
log_,
resolver_timeout_,
25000,
resolver_,
thread_system(),
message_handler());
ngx_url_async_fetcher_ = fetcher;
NgxUrlAsyncFetcher* fetcher = new NgxUrlAsyncFetcher(
config->fetcher_proxy().c_str(),
log_,
resolver_timeout_,
config->blocking_fetch_timeout_ms(),
resolver_,
native_fetcher_max_keepalive_requests_,
thread_system(),
message_handler());
ngx_url_async_fetchers_.push_back(fetcher);
return fetcher;
} else {
net_instaweb::SerfUrlAsyncFetcher* fetcher =
new net_instaweb::SerfUrlAsyncFetcher(
fetcher_proxy,
NULL,
thread_system(),
statistics(),
timer(),
2500,
message_handler());
// Make sure we don't block the nginx event loop
fetcher->set_force_threaded(true);
return fetcher;
return SystemRewriteDriverFactory::AllocateFetcher(config);
}
}
@@ -179,43 +148,19 @@ NamedLockManager* NgxRewriteDriverFactory::DefaultLockManager() {
return NULL;
}
void NgxRewriteDriverFactory::SetupCaches(ServerContext* server_context) {
caches_->SetupCaches(server_context);
server_context->set_enable_property_cache(true);
PropertyCache* pcache = server_context->page_property_cache();
if (pcache->GetCohort(RewriteDriver::kBeaconCohort) == NULL) {
pcache->AddCohort(RewriteDriver::kBeaconCohort);
}
if (pcache->GetCohort(RewriteDriver::kDomCohort) == NULL) {
pcache->AddCohort(RewriteDriver::kDomCohort);
}
}
RewriteOptions* NgxRewriteDriverFactory::NewRewriteOptions() {
NgxRewriteOptions* options = new NgxRewriteOptions();
NgxRewriteOptions* options = new NgxRewriteOptions(thread_system());
// TODO(jefftk): figure out why using SetDefaultRewriteLevel like
// mod_pagespeed does in mod_instaweb.cc:create_dir_config() isn't enough here
// -- if you use that instead then ngx_pagespeed doesn't actually end up
// defaulting CoreFilters.
// See: https://github.com/apache/incubator-pagespeed-ngx/issues/1190
options->SetRewriteLevel(RewriteOptions::kCoreFilters);
return options;
}
void NgxRewriteDriverFactory::InitStaticAssetManager(
StaticAssetManager* static_asset_manager) {
static_asset_manager->set_library_url_prefix(kStaticAssetPrefix);
}
void NgxRewriteDriverFactory::PrintMemCacheStats(GoogleString* out) {
// TODO(morlovich): Port the client code to proper API, so it gets
// shm stats, too.
caches_->PrintCacheStats(SystemCaches::kIncludeMemcached, out);
}
bool NgxRewriteDriverFactory::InitNgxUrlAsyncFetcher() {
if (ngx_url_async_fetcher_ == NULL) {
return true;
}
log_ = ngx_cycle->log;
return ngx_url_async_fetcher_->Init();
RewriteOptions* NgxRewriteDriverFactory::NewRewriteOptionsForQuery() {
return new NgxRewriteOptions(thread_system());
}
bool NgxRewriteDriverFactory::CheckResolver() {
@@ -225,52 +170,46 @@ bool NgxRewriteDriverFactory::CheckResolver() {
return true;
}
void NgxRewriteDriverFactory::StopCacheActivity() {
RewriteDriverFactory::StopCacheActivity();
caches_->StopCacheActivity();
}
NgxServerContext* NgxRewriteDriverFactory::MakeNgxServerContext() {
NgxServerContext* server_context = new NgxServerContext(this);
NgxServerContext* NgxRewriteDriverFactory::MakeNgxServerContext(
StringPiece hostname, int port) {
NgxServerContext* server_context = new NgxServerContext(this, hostname, port);
uninitialized_server_contexts_.insert(server_context);
return server_context;
}
ServerContext* NgxRewriteDriverFactory::NewDecodingServerContext() {
ServerContext* sc = new NgxServerContext(this, hostname_, port_);
InitStubDecodingServerContext(sc);
return sc;
}
ServerContext* NgxRewriteDriverFactory::NewServerContext() {
LOG(DFATAL) << "MakeNgxServerContext should be used instead";
return NULL;
}
void NgxRewriteDriverFactory::ShutDown() {
StopCacheActivity();
if (!is_root_process_) {
Variable* child_shutdown_count = statistics()->GetVariable(kShutdownCount);
child_shutdown_count->Add(1);
if (!shut_down_) {
shut_down_ = true;
SystemRewriteDriverFactory::ShutDown();
}
}
RewriteDriverFactory::ShutDown();
caches_->ShutDown(message_handler());
void NgxRewriteDriverFactory::ShutDownMessageHandlers() {
ngx_message_handler_->set_buffer(NULL);
ngx_html_parse_message_handler_->set_buffer(NULL);
if (is_root_process_) {
// Cleanup statistics.
// TODO(morlovich): This looks dangerous with async.
if (shared_mem_statistics_.get() != NULL) {
shared_mem_statistics_->GlobalCleanup(message_handler());
}
if (shared_circular_buffer_ != NULL) {
shared_circular_buffer_->GlobalCleanup(message_handler());
}
for (NgxMessageHandlerSet::iterator p =
server_context_message_handlers_.begin();
p != server_context_message_handlers_.end(); ++p) {
(*p)->set_buffer(NULL);
}
server_context_message_handlers_.clear();
}
void NgxRewriteDriverFactory::StartThreads() {
if (threads_started_) {
return;
}
ngx_thread_system_->PermitThreadStarting();
// TODO(jefftk): use a native nginx timer instead of running our own thread.
// See issue #111.
SchedulerThread* thread = new SchedulerThread(thread_system(), scheduler());
@@ -280,114 +219,73 @@ void NgxRewriteDriverFactory::StartThreads() {
threads_started_ = true;
}
void NgxRewriteDriverFactory::ParentOrChildInit(ngx_log_t* log) {
if (install_crash_handler_) {
void NgxRewriteDriverFactory::SetMainConf(NgxRewriteOptions* main_options) {
// Propagate process-scope options from the copy we had during nginx option
// parsing to our own.
if (main_options != NULL) {
default_options()->MergeOnlyProcessScopeOptions(*main_options);
}
}
void NgxRewriteDriverFactory::LoggingInit(
ngx_log_t* log, bool may_install_crash_handler) {
log_ = log;
net_instaweb::log_message_handler::Install(log);
if (may_install_crash_handler && install_crash_handler()) {
NgxMessageHandler::InstallCrashHandler(log);
}
ngx_message_handler_->set_log(log);
ngx_html_parse_message_handler_->set_log(log);
SharedCircularBufferInit(is_root_process_);
}
// TODO(jmarantz): make this per-vhost.
void NgxRewriteDriverFactory::SharedCircularBufferInit(bool is_root) {
// Set buffer size to 0 means turning it off
if (shared_mem_runtime() != NULL && (message_buffer_size_ != 0)) {
// TODO(jmarantz): it appears that filename_prefix() is not actually
// established at the time of this construction, calling into question
// whether we are naming our shared-memory segments correctly.
shared_circular_buffer_.reset(new SharedCircularBuffer(
shared_mem_runtime(),
message_buffer_size_,
filename_prefix().as_string(),
"foo.com" /*hostname_identifier()*/));
if (shared_circular_buffer_->InitSegment(is_root, message_handler())) {
ngx_message_handler_->set_buffer(shared_circular_buffer_.get());
ngx_html_parse_message_handler_->set_buffer(
shared_circular_buffer_.get());
}
}
void NgxRewriteDriverFactory::SetCircularBuffer(
SharedCircularBuffer* buffer) {
ngx_shared_circular_buffer_ = buffer;
ngx_message_handler_->set_buffer(buffer);
ngx_html_parse_message_handler_->set_buffer(buffer);
}
void NgxRewriteDriverFactory::RootInit(ngx_log_t* log) {
net_instaweb::log_message_handler::Install(log);
ParentOrChildInit(log);
// Let SystemCaches know about the various paths we have in configuration
// first, as well as the memcached instances.
for (NgxServerContextSet::iterator p = uninitialized_server_contexts_.begin(),
e = uninitialized_server_contexts_.end(); p != e; ++p) {
NgxServerContext* server_context = *p;
caches_->RegisterConfig(server_context->config());
}
caches_->RootInit();
}
void NgxRewriteDriverFactory::ChildInit(ngx_log_t* log) {
is_root_process_ = false;
ParentOrChildInit(log);
if (shared_mem_statistics_.get() != NULL) {
shared_mem_statistics_->Init(false, message_handler());
}
caches_->ChildInit();
for (NgxServerContextSet::iterator p = uninitialized_server_contexts_.begin(),
e = uninitialized_server_contexts_.end(); p != e; ++p) {
NgxServerContext* server_context = *p;
server_context->ChildInit();
}
uninitialized_server_contexts_.clear();
}
// Initializes global statistics object if needed, using factory to
// help with the settings if needed.
// Note: does not call set_statistics() on the factory.
Statistics* NgxRewriteDriverFactory::MakeGlobalSharedMemStatistics(
bool logging, int64 logging_interval_ms,
const GoogleString& logging_file_base) {
if (shared_mem_statistics_.get() == NULL) {
shared_mem_statistics_.reset(AllocateAndInitSharedMemStatistics(
"global", logging, logging_interval_ms, logging_file_base));
}
DCHECK(!statistics_frozen_);
statistics_frozen_ = true;
SetStatistics(shared_mem_statistics_.get());
return shared_mem_statistics_.get();
}
SharedMemStatistics* NgxRewriteDriverFactory::
AllocateAndInitSharedMemStatistics(
const StringPiece& name, const bool logging,
const int64 logging_interval_ms,
const GoogleString& logging_file_base) {
// Note that we create the statistics object in the parent process, and
// it stays around in the kids but gets reinitialized for them
// inside ChildInit(), called from pagespeed_child_init.
SharedMemStatistics* stats = new SharedMemStatistics(
logging_interval_ms, StrCat(logging_file_base, name), logging,
StrCat(filename_prefix(), name), shared_mem_runtime(), message_handler(),
file_system(), timer());
InitStats(stats);
stats->Init(true, message_handler());
return stats;
void NgxRewriteDriverFactory::SetServerContextMessageHandler(
ServerContext* server_context, ngx_log_t* log) {
NgxMessageHandler* handler = new NgxMessageHandler(
timer(), thread_system()->NewMutex());
handler->set_log(log);
// The ngx_shared_circular_buffer_ will be NULL if MessageBufferSize hasn't
// been raised from its default of 0.
handler->set_buffer(ngx_shared_circular_buffer_);
server_context_message_handlers_.insert(handler);
defer_cleanup(new Deleter<NgxMessageHandler>(handler));
server_context->set_message_handler(handler);
}
void NgxRewriteDriverFactory::InitStats(Statistics* statistics) {
// Init standard PSOL stats.
SystemRewriteDriverFactory::InitStats(statistics);
RewriteDriverFactory::InitStats(statistics);
RateController::InitStats(statistics);
// Init Ngx-specific stats.
NgxServerContext::InitStats(statistics);
SystemCaches::InitStats(statistics);
SerfUrlAsyncFetcher::InitStats(statistics);
PropertyCache::InitCohortStats(RewriteDriver::kBeaconCohort, statistics);
PropertyCache::InitCohortStats(RewriteDriver::kDomCohort, statistics);
InPlaceResourceRecorder::InitStats(statistics);
}
statistics->AddVariable(kShutdownCount);
void NgxRewriteDriverFactory::PrepareForkedProcess(const char* name) {
ngx_pid = ngx_getpid(); // Needed for logging to have the right PIDs.
SystemRewriteDriverFactory::PrepareForkedProcess(name);
}
void NgxRewriteDriverFactory::NameProcess(const char* name) {
SystemRewriteDriverFactory::NameProcess(name);
// Superclass set status with prctl. Nginx has a helper function for setting
// argv[0] as well, so let's use that. We'll show up as:
//
// nginx: pagespeed $name
char name_for_setproctitle[32];
snprintf(name_for_setproctitle, sizeof(name_for_setproctitle),
"pagespeed %s", name);
ngx_setproctitle(name_for_setproctitle);
}
} // namespace net_instaweb
+89 -130
View File
@@ -1,25 +1,32 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: jefftk@google.com (Jeff Kaufman)
#ifndef NGX_REWRITE_DRIVER_FACTORY_H_
#define NGX_REWRITE_DRIVER_FACTORY_H_
extern "C" {
#include <ngx_auto_config.h>
#if (NGX_THREADS)
#include <ngx_thread.h>
#endif
#include <ngx_core.h>
#include <ngx_http.h>
#include <ngx_config.h>
@@ -28,134 +35,73 @@ extern "C" {
#include <set>
#include "apr_pools.h"
#include "net/instaweb/system/public/system_rewrite_driver_factory.h"
#include "net/instaweb/util/public/md5_hasher.h"
#include "net/instaweb/util/public/scoped_ptr.h"
// TODO(oschaaf): We should reparent ApacheRewriteDriverFactory and
// NgxRewriteDriverFactory to a new class OriginRewriteDriverFactory and factor
// out as much as possible.
#include "pagespeed/kernel/base/md5_hasher.h"
#include "pagespeed/kernel/base/scoped_ptr.h"
#include "pagespeed/system/system_rewrite_driver_factory.h"
namespace net_instaweb {
class AbstractSharedMem;
class NgxMessageHandler;
class NgxRewriteOptions;
class NgxServerContext;
class NgxThreadSystem;
class NgxUrlAsyncFetcher;
class SharedCircularBuffer;
class SharedMemRefererStatistics;
class SharedMemStatistics;
class SlowWorker;
class StaticAssetManager;
class Statistics;
class SystemCaches;
class SystemThreadSystem;
enum ProcessScriptVariablesMode {
kOff,
kLegacyRestricted,
kAll
};
class NgxRewriteDriverFactory : public SystemRewriteDriverFactory {
public:
static const char kStaticAssetPrefix[];
// We take ownership of the thread system.
explicit NgxRewriteDriverFactory(NgxThreadSystem* ngx_thread_system);
explicit NgxRewriteDriverFactory(
const ProcessContext& process_context,
SystemThreadSystem* system_thread_system, StringPiece hostname, int port);
virtual ~NgxRewriteDriverFactory();
virtual Hasher* NewHasher();
virtual UrlFetcher* DefaultUrlFetcher();
virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
virtual UrlAsyncFetcher* AllocateFetcher(SystemRewriteOptions* config);
virtual MessageHandler* DefaultHtmlParseMessageHandler();
virtual MessageHandler* DefaultMessageHandler();
virtual FileSystem* DefaultFileSystem();
virtual Timer* DefaultTimer();
virtual NamedLockManager* DefaultLockManager();
virtual void SetupCaches(ServerContext* server_context);
// Create a new RewriteOptions. In this implementation it will be an
// NgxRewriteOptions.
// NgxRewriteOptions, and it will have CoreFilters explicitly set.
virtual RewriteOptions* NewRewriteOptions();
// Initializes the StaticAssetManager.
virtual void InitStaticAssetManager(
StaticAssetManager* static_asset_manager);
// Print out details of all the connections to memcached servers.
void PrintMemCacheStats(GoogleString* out);
bool InitNgxUrlAsyncFetcher();
virtual RewriteOptions* NewRewriteOptionsForQuery();
virtual ServerContext* NewDecodingServerContext();
// Check resolver configured or not.
bool CheckResolver();
// Release all the resources. It also calls the base class ShutDown to
// release the base class resources.
// Initializes all the statistics objects created transitively by
// NgxRewriteDriverFactory, including nginx-specific and
// platform-independent statistics.
static void InitStats(Statistics* statistics);
NgxServerContext* MakeNgxServerContext(StringPiece hostname, int port);
virtual ServerContext* NewServerContext();
virtual void ShutDown();
virtual void StopCacheActivity();
NgxServerContext* MakeNgxServerContext();
ServerContext* NewServerContext();
AbstractSharedMem* shared_mem_runtime() const {
return shared_mem_runtime_.get();
}
SystemCaches* caches() { return caches_.get(); }
// Starts pagespeed threads if they've not been started already. Must be
// called after the caller has finished any forking it intends to do.
void StartThreads();
// This helper method contains init procedures invoked by both RootInit()
// and ChildInit()
void ParentOrChildInit(ngx_log_t* log);
// For shared memory resources the general setup we follow is to have the
// first running process (aka the root) create the necessary segments and
// fill in their shared data structures, while processes created to actually
// handle requests attach to already existing shared data structures.
//
// During normal server startup[1], RootInit() is called from the nginx hooks
// in the root process for the first task, and then ChildInit() is called in
// any child process.
//
// Keep in mind, however, that when fork() is involved a process may
// effectively see both calls, in which case the 'ChildInit' call would
// come second and override the previous root status. Both calls are also
// invoked in the debug single-process mode.
//
// [1] Besides normal startup, nginx also uses a temporary process to
// syntax check the config file. That basically looks like a complete
// normal startup and shutdown to the code.
bool is_root_process() const { return is_root_process_; }
void RootInit(ngx_log_t* log);
void ChildInit(ngx_log_t* log);
void SharedCircularBufferInit(bool is_root);
// Build global shared-memory statistics. This is invoked if at least
// one server context (global or VirtualHost) enables statistics.
Statistics* MakeGlobalSharedMemStatistics(bool logging,
int64 logging_interval_ms,
const GoogleString& logging_file);
// Creates and ::Initializes a shared memory statistics object.
SharedMemStatistics* AllocateAndInitSharedMemStatistics(
const StringPiece& name, const bool logging,
const int64 logging_interval_ms, const GoogleString& logging_file);
void SetServerContextMessageHandler(ServerContext* server_context,
ngx_log_t* log);
NgxMessageHandler* ngx_message_handler() { return ngx_message_handler_; }
void set_main_conf(NgxRewriteOptions* main_conf) { main_conf_ = main_conf; }
bool use_per_vhost_statistics() const {
return use_per_vhost_statistics_;
}
void set_use_per_vhost_statistics(bool x) {
use_per_vhost_statistics_ = x;
}
bool install_crash_handler() const {
return install_crash_handler_;
}
void set_install_crash_handler(bool x) {
install_crash_handler_ = x;
}
bool message_buffer_size() const {
return message_buffer_size_;
}
void set_message_buffer_size(int x) {
message_buffer_size_ = x;
virtual void NonStaticInitStats(Statistics* statistics) {
InitStats(statistics);
}
void SetMainConf(NgxRewriteOptions* main_conf);
void set_resolver(ngx_resolver_t* resolver) {
resolver_ = resolver;
}
@@ -169,48 +115,61 @@ class NgxRewriteDriverFactory : public SystemRewriteDriverFactory {
void set_use_native_fetcher(bool x) {
use_native_fetcher_ = x;
}
// We use a beacon handler to collect data for critical images,
// css, etc., so filters should be configured accordingly.
//
// TODO(jefftk): move to SystemRewriteDriverFactory
virtual bool UseBeaconResultsInFilters() const {
return true;
int native_fetcher_max_keepalive_requests() {
return native_fetcher_max_keepalive_requests_;
}
void set_native_fetcher_max_keepalive_requests(int x) {
native_fetcher_max_keepalive_requests_ = x;
}
ProcessScriptVariablesMode process_script_variables() {
return process_script_variables_mode_;
}
void LoggingInit(ngx_log_t* log, bool may_install_crash_handler);
virtual void ShutDownMessageHandlers();
virtual void SetCircularBuffer(SharedCircularBuffer* buffer);
bool SetProcessScriptVariables(ProcessScriptVariablesMode mode) {
if (!process_script_variables_set_) {
process_script_variables_mode_ = mode;
process_script_variables_set_ = true;
return true;
}
return false;
}
virtual void PrepareForkedProcess(const char* name);
virtual void NameProcess(const char* name);
private:
NgxThreadSystem* ngx_thread_system_;
Timer* timer_;
scoped_ptr<AbstractSharedMem> shared_mem_runtime_;
// main_conf will have only options set in the main block. It may be NULL,
// and we do not take ownership.
NgxRewriteOptions* main_conf_;
typedef std::set<NgxServerContext*> NgxServerContextSet;
NgxServerContextSet uninitialized_server_contexts_;
// Manages all our caches & lock managers.
scoped_ptr<SystemCaches> caches_;
bool threads_started_;
// If true, we'll have a separate statistics object for each vhost
// (along with a global aggregate), rather than just a single object
// aggregating all of them.
bool use_per_vhost_statistics_;
bool is_root_process_;
NgxMessageHandler* ngx_message_handler_;
NgxMessageHandler* ngx_html_parse_message_handler_;
bool install_crash_handler_;
int message_buffer_size_;
scoped_ptr<SharedCircularBuffer> shared_circular_buffer_;
scoped_ptr<SharedMemStatistics> shared_mem_statistics_;
bool statistics_frozen_;
NgxUrlAsyncFetcher* ngx_url_async_fetcher_;
std::vector<NgxUrlAsyncFetcher*> ngx_url_async_fetchers_;
ngx_log_t* log_;
ngx_msec_t resolver_timeout_;
ngx_resolver_t* resolver_;
bool use_native_fetcher_;
int native_fetcher_max_keepalive_requests_;
typedef std::set<NgxMessageHandler*> NgxMessageHandlerSet;
NgxMessageHandlerSet server_context_message_handlers_;
// Owned by the superclass.
// TODO(jefftk): merge the nginx and apache ways of doing this.
SharedCircularBuffer* ngx_shared_circular_buffer_;
GoogleString hostname_;
int port_;
ProcessScriptVariablesMode process_script_variables_mode_;
bool process_script_variables_set_;
bool shut_down_;
DISALLOW_COPY_AND_ASSIGN(NgxRewriteDriverFactory);
};
+426 -125
View File
@@ -1,20 +1,23 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: jefftk@google.com (Jeff Kaufman)
#include "ngx_rewrite_options.h"
@@ -30,36 +33,113 @@ extern "C" {
#include "net/instaweb/public/version.h"
#include "net/instaweb/rewriter/public/file_load_policy.h"
#include "net/instaweb/rewriter/public/rewrite_options.h"
#include "net/instaweb/system/public/system_caches.h"
#include "net/instaweb/util/public/timer.h"
#include "pagespeed/kernel/base/message_handler.h"
#include "pagespeed/kernel/base/timer.h"
#include "pagespeed/system/system_caches.h"
namespace net_instaweb {
namespace {
const char kStatisticsPath[] = "StatisticsPath";
const char kGlobalStatisticsPath[] = "GlobalStatisticsPath";
const char kConsolePath[] = "ConsolePath";
const char kMessagesPath[] = "MessagesPath";
const char kAdminPath[] = "AdminPath";
const char kGlobalAdminPath[] = "GlobalAdminPath";
// These options are copied from mod_instaweb.cc, where APACHE_CONFIG_OPTIONX
// indicates that they can not be set at the directory/location level. They set
// options in the RewriteDriverFactory, so they're entirely global and do not
// appear in RewriteOptions. They are not alphabetized on purpose, but rather
// left in the same order as in mod_instaweb.cc in case we end up needing to
// compare.
// TODO(oschaaf): this duplication is a short term solution.
const char* const server_only_options[] = {
"FetcherTimeoutMs",
"FetchProxy",
"ForceCaching",
"GeneratedFilePrefix",
"ImgMaxRewritesAtOnce",
"InheritVHostConfig",
"InstallCrashHandler",
"MessageBufferSize",
"NumRewriteThreads",
"NumExpensiveRewriteThreads",
"StaticAssetPrefix",
"TrackOriginalContentLength",
"UsePerVHostStatistics", // TODO(anupama): What to do about "No longer used"
"BlockingRewriteRefererUrls",
"CreateSharedMemoryMetadataCache",
"LoadFromFile",
"LoadFromFileMatch",
"LoadFromFileRule",
"LoadFromFileRuleMatch",
"UseNativeFetcher",
"NativeFetcherMaxKeepaliveRequests"
};
// Options that can only be used in the main (http) option scope.
const char* const main_only_options[] = {
"UseNativeFetcher",
"NativeFetcherMaxKeepaliveRequests"
};
} // namespace
RewriteOptions::Properties* NgxRewriteOptions::ngx_properties_ = NULL;
NgxRewriteOptions::NgxRewriteOptions() {
NgxRewriteOptions::NgxRewriteOptions(const StringPiece& description,
ThreadSystem* thread_system)
: SystemRewriteOptions(description, thread_system) {
Init();
}
NgxRewriteOptions::NgxRewriteOptions(ThreadSystem* thread_system)
: SystemRewriteOptions(thread_system) {
Init();
}
void NgxRewriteOptions::Init() {
DCHECK(ngx_properties_ != NULL)
<< "Call NgxRewriteOptions::Initialize() before construction";
clear_inherited_scripts_ = false;
InitializeOptions(ngx_properties_);
}
void NgxRewriteOptions::AddProperties() {
// Nothing ngx-specific for now.
// Nginx-specific options.
add_ngx_option(
"", &NgxRewriteOptions::statistics_path_, "nsp", kStatisticsPath,
kServerScope, "Set the statistics path. Ex: /ngx_pagespeed_statistics",
false);
add_ngx_option(
"", &NgxRewriteOptions::global_statistics_path_, "ngsp",
kGlobalStatisticsPath, kProcessScopeStrict,
"Set the global statistics path. Ex: /ngx_pagespeed_global_statistics",
false);
add_ngx_option(
"", &NgxRewriteOptions::console_path_, "ncp", kConsolePath, kServerScope,
"Set the console path. Ex: /pagespeed_console", false);
add_ngx_option(
"", &NgxRewriteOptions::messages_path_, "nmp", kMessagesPath,
kServerScope, "Set the messages path. Ex: /ngx_pagespeed_message",
false);
add_ngx_option(
"", &NgxRewriteOptions::admin_path_, "nap", kAdminPath,
kServerScope, "Set the admin path. Ex: /pagespeed_admin", false);
add_ngx_option(
"", &NgxRewriteOptions::global_admin_path_, "ngap", kGlobalAdminPath,
kProcessScopeStrict,
"Set the global admin path. Ex: /pagespeed_global_admin",
false);
MergeSubclassProperties(ngx_properties_);
NgxRewriteOptions config;
config.InitializeSignaturesAndDefaults();
}
void NgxRewriteOptions::InitializeSignaturesAndDefaults() {
// Calls to foo_.DoNotUseForSignatureComputation() would go here.
// Set default header value.
set_default_x_header_value(kModPagespeedVersion);
// Default properties are global but to set them the current API requires
// a RewriteOptions instance and we're in a static method.
NgxRewriteOptions dummy_config(NULL);
dummy_config.set_default_x_header_value(kModPagespeedVersion);
}
void NgxRewriteOptions::Initialize() {
@@ -80,55 +160,114 @@ bool NgxRewriteOptions::IsDirective(StringPiece config_directive,
return StringCaseEqual(config_directive, compare_directive);
}
RewriteOptions::OptionScope NgxRewriteOptions::GetOptionScope(
StringPiece option_name) {
ngx_uint_t i;
ngx_uint_t size = sizeof(main_only_options) / sizeof(char*);
for (i = 0; i < size; i++) {
if (StringCaseEqual(main_only_options[i], option_name)) {
return kProcessScopeStrict;
}
}
size = sizeof(server_only_options) / sizeof(char*);
for (i = 0; i < size; i++) {
if (StringCaseEqual(server_only_options[i], option_name)) {
return kServerScope;
}
}
// This could be made more efficient if RewriteOptions provided a map allowing
// access of options by their name. It's not too much of a worry at present
// since this is just during initialization.
for (OptionBaseVector::const_iterator it = all_options().begin();
it != all_options().end(); ++it) {
RewriteOptions::OptionBase* option = *it;
if (option->option_name() == option_name) {
// We treat kLegacyProcessScope as kProcessScopeStrict, failing to start
// if an option is out of place.
return option->scope() == kLegacyProcessScope ? kProcessScopeStrict
: option->scope();
}
}
return kDirectoryScope;
}
RewriteOptions::OptionSettingResult NgxRewriteOptions::ParseAndSetOptions0(
StringPiece directive, GoogleString* msg, MessageHandler* handler) {
if (IsDirective(directive, "on")) {
set_enabled(RewriteOptions::kEnabledOn);
} else if (IsDirective(directive, "off")) {
set_enabled(RewriteOptions::kEnabledOff);
} else if (IsDirective(directive, "unplugged")) {
set_enabled(RewriteOptions::kEnabledUnplugged);
} else {
EnabledEnum enabled;
if (!ParseFromString(directive, &enabled)) {
return RewriteOptions::kOptionNameUnknown;
}
if (enabled == RewriteOptions::kEnabledOff) {
// In ngx_pagespeed, for historical reasons, we treat "off" as "unplugged".
// Also, "off" is deprecated and people should be using "standby" or
// "unplugged" now depending on which sense they want. See comment on
// RewriteOptions::EnabledEnum.
enabled = RewriteOptions::kEnabledUnplugged;
}
set_enabled(enabled);
return RewriteOptions::kOptionOk;
}
RewriteOptions::OptionSettingResult
NgxRewriteOptions::ParseAndSetOptionFromEnum1(
OptionEnum directive, StringPiece arg,
NgxRewriteOptions::ParseAndSetOptionFromName1(
StringPiece name, StringPiece arg,
GoogleString* msg, MessageHandler* handler) {
// FileCachePath needs error checking.
if (directive == kFileCachePath) {
if (StringCaseEqual(name, kFileCachePath)) {
if (!StringCaseStartsWith(arg, "/")) {
*msg = "must start with a slash";
return RewriteOptions::kOptionValueInvalid;
}
}
// TODO(jefftk): port these (no enums for them yet, even!)
// DangerPermitFetchFromUnknownHosts, FetchWithGzip, ForceCaching
return SystemRewriteOptions::ParseAndSetOptionFromEnum1(
directive, arg, msg, handler);
return SystemRewriteOptions::ParseAndSetOptionFromName1(
name, arg, msg, handler);
}
// Very similar to apache/mod_instaweb::ParseDirective.
const char*
NgxRewriteOptions::ParseAndSetOptions(
StringPiece* args, int n_args, ngx_pool_t* pool, MessageHandler* handler,
NgxRewriteDriverFactory* driver_factory) {
CHECK_GE(n_args, 1);
int i;
fprintf(stderr, "Setting option from (");
for (i = 0 ; i < n_args ; i++) {
fprintf(stderr, "%s\"%s\"",
i == 0 ? "" : ", ",
args[i].as_string().c_str());
template <class DriverFactoryT>
RewriteOptions::OptionSettingResult ParseAndSetOptionHelper(
StringPiece option_value,
DriverFactoryT* driver_factory,
void (DriverFactoryT::*set_option_method)(bool)) {
bool parsed_value;
if (StringCaseEqual(option_value, "on") ||
StringCaseEqual(option_value, "true")) {
parsed_value = true;
} else if (StringCaseEqual(option_value, "off") ||
StringCaseEqual(option_value, "false")) {
parsed_value = false;
} else {
return RewriteOptions::kOptionValueInvalid;
}
fprintf(stderr, ")\n");
(driver_factory->*set_option_method)(parsed_value);
return RewriteOptions::kOptionOk;
}
namespace {
const char* ps_error_string_for_option(
ngx_pool_t* pool, StringPiece directive, StringPiece warning) {
GoogleString msg =
StrCat("\"", directive, "\" ", warning);
char* s = string_piece_to_pool_string(pool, msg);
if (s == NULL) {
return "failed to allocate memory";
}
return s;
}
} // namespace
// Very similar to apache/mod_instaweb::ParseDirective.
const char* NgxRewriteOptions::ParseAndSetOptions(
StringPiece* args, int n_args, ngx_pool_t* pool, MessageHandler* handler,
NgxRewriteDriverFactory* driver_factory,
RewriteOptions::OptionScope scope, ngx_conf_t* cf,
ProcessScriptVariablesMode script_mode) {
CHECK_GE(n_args, 1);
StringPiece directive = args[0];
@@ -138,100 +277,186 @@ NgxRewriteOptions::ParseAndSetOptions(
directive.remove_prefix(mod_pagespeed.size());
}
if (GetOptionScope(directive) > scope) {
return ps_error_string_for_option(
pool, directive, "cannot be set at this scope.");
}
bool compile_scripts = false;
if (script_mode != ProcessScriptVariablesMode::kOff) {
// In the old mode we only allowed a few, so restrict to those.
compile_scripts =
StringCaseStartsWith(directive, "LoadFromFile") ||
StringCaseEqual(directive, "EnableFilters") ||
StringCaseEqual(directive, "DisableFilters") ||
StringCaseEqual(directive, "DownstreamCachePurgeLocationPrefix") ||
StringCaseEqual(directive, "DownstreamCachePurgeMethod") ||
StringCaseEqual(directive,
"DownstreamCacheRewrittenPercentageThreshold") ||
StringCaseEqual(directive, "ShardDomain");
// In the new behaviour we also allow scripting of query- and directory-
// scoped options.
compile_scripts |=
script_mode == ProcessScriptVariablesMode::kAll &&
(GetOptionScope(directive) <= RewriteOptions::kDirectoryScope ||
(StringCaseEqual(directive, "Allow") ||
StringCaseEqual(directive, "BlockingRewriteRefererUrls") ||
StringCaseEqual(directive, "Disallow") ||
StringCaseEqual(directive, "DistributableFilters") ||
StringCaseEqual(directive, "Domain") ||
StringCaseEqual(directive, "ExperimentVariable") ||
StringCaseEqual(directive, "ExperimentSpec") ||
StringCaseEqual(directive, "ForbidFilters") ||
StringCaseEqual(directive, "RetainComment") ||
StringCaseEqual(directive, "CustomFetchHeader") ||
StringCaseEqual(directive, "MapOriginDomain") ||
StringCaseEqual(directive, "MapProxyDomain") ||
StringCaseEqual(directive, "MapRewriteDomain") ||
StringCaseEqual(directive, "UrlValuedAttribute") ||
StringCaseEqual(directive, "Library")));
}
ScriptLine* script_line;
script_line = NULL;
if (n_args == 1 && StringCaseEqual(directive, "ClearInheritedScripts")) {
clear_inherited_scripts_ = true;
return NGX_CONF_OK;
}
if (compile_scripts) {
CHECK(cf != NULL);
int i;
// Skip the first arg which is always 'pagespeed'
for (i = 1; i < n_args; i++) {
ngx_str_t script_source;
script_source.len = args[i].as_string().length();
std::string tmp = args[i].as_string();
script_source.data = reinterpret_cast<u_char*>(
const_cast<char*>(tmp.c_str()));
if (ngx_http_script_variables_count(&script_source) > 0) {
ngx_http_script_compile_t* sc =
reinterpret_cast<ngx_http_script_compile_t*>(
ngx_pcalloc(cf->pool, sizeof(ngx_http_script_compile_t)));
sc->cf = cf;
sc->source = &script_source;
sc->lengths = reinterpret_cast<ngx_array_t**>(
ngx_pcalloc(cf->pool, sizeof(ngx_array_t*)));
sc->values = reinterpret_cast<ngx_array_t**>(
ngx_pcalloc(cf->pool, sizeof(ngx_array_t*)));
sc->variables = 1;
sc->complete_lengths = 1;
sc->complete_values = 1;
if (ngx_http_script_compile(sc) != NGX_OK) {
return ps_error_string_for_option(
pool, directive, "Failed to compile script variables");
} else {
if (script_line == NULL) {
script_line = new ScriptLine(args, n_args, scope);
}
script_line->AddScriptAndArgIndex(sc, i);
}
}
}
if (script_line != NULL) {
script_lines_.push_back(RefCountedPtr<ScriptLine>(script_line));
// We have found script variables in the current configuration line, and
// prepared the associated rewriteoptions for that.
// We will defer parsing, validation and processing of this line to
// request time. That means we are done handling this configuration line.
return NGX_CONF_OK;
}
}
GoogleString msg;
OptionSettingResult result;
if (n_args == 1) {
result = ParseAndSetOptions0(directive, &msg, handler);
} else if (n_args == 2) {
StringPiece arg = args[1];
// TODO(morlovich): Remove these special hacks, and handle these via
// ParseAndSetOptionFromEnum1.
if (IsDirective(directive, "UsePerVHostStatistics")) {
// TODO(oschaaf): mod_pagespeed has a nicer way to do this.
if (IsDirective(arg, "on")) {
driver_factory->set_use_per_vhost_statistics(true);
result = RewriteOptions::kOptionOk;
} else if (IsDirective(arg, "off")) {
driver_factory->set_use_per_vhost_statistics(false);
result = RewriteOptions::kOptionOk;
} else {
result = RewriteOptions::kOptionValueInvalid;
}
} else if (IsDirective(directive, "InstallCrashHandler")) {
// TODO(oschaaf): mod_pagespeed has a nicer way to do this.
if (IsDirective(arg, "on")) {
driver_factory->set_install_crash_handler(true);
result = RewriteOptions::kOptionOk;
} else if (IsDirective(arg, "off")) {
driver_factory->set_install_crash_handler(false);
result = RewriteOptions::kOptionOk;
} else {
result = RewriteOptions::kOptionValueInvalid;
}
} else if (IsDirective(directive, "MessageBufferSize")) {
// TODO(oschaaf): mod_pagespeed has a nicer way to do this.
int message_buffer_size;
bool ok = StringToInt(arg.as_string(), &message_buffer_size);
if (ok && message_buffer_size >= 0) {
driver_factory->set_message_buffer_size(message_buffer_size);
result = RewriteOptions::kOptionOk;
} else {
result = RewriteOptions::kOptionValueInvalid;
}
} else if (IsDirective(directive, "UseNativeFetcher")) {
// TODO(oschaaf): mod_pagespeed has a nicer way to do this.
if (IsDirective(arg, "on")) {
driver_factory->set_use_native_fetcher(true);
result = RewriteOptions::kOptionOk;
} else if (IsDirective(arg, "off")) {
driver_factory->set_use_native_fetcher(false);
result = RewriteOptions::kOptionOk;
} else {
result = RewriteOptions::kOptionValueInvalid;
}
if (IsDirective(directive, "UseNativeFetcher")) {
result = ParseAndSetOptionHelper<NgxRewriteDriverFactory>(
arg, driver_factory,
&NgxRewriteDriverFactory::set_use_native_fetcher);
} else if (IsDirective(directive, "NativeFetcherMaxKeepaliveRequests")) {
int max_keepalive_requests;
if (StringToInt(arg, &max_keepalive_requests) &&
max_keepalive_requests > 0) {
driver_factory->set_native_fetcher_max_keepalive_requests(
max_keepalive_requests);
result = RewriteOptions::kOptionOk;
} else {
result = ParseAndSetOptionFromName1(directive, args[1], &msg, handler);
}
} else if (n_args == 3) {
// Short-term special handling, until this moves to common code.
// TODO(morlovich): Clean this up.
if (StringCaseEqual(directive, "CreateSharedMemoryMetadataCache")) {
int64 kb = 0;
if (!StringToInt64(args[2], &kb) || kb < 0) {
result = RewriteOptions::kOptionValueInvalid;
msg = "size_kb must be a positive 64-bit integer";
}
} else if (StringCaseEqual("ProcessScriptVariables", args[0])) {
if (scope == RewriteOptions::kProcessScopeStrict) {
ProcessScriptVariablesMode mode;
if (StringCaseEqual(arg, "all")) {
mode = ProcessScriptVariablesMode::kAll;
} else if (StringCaseEqual(arg, "on")) {
mode = ProcessScriptVariablesMode::kLegacyRestricted;
} else if (StringCaseEqual(arg, "off")) {
mode = ProcessScriptVariablesMode::kOff;
} else {
return const_cast<char*>(
"pagespeed ProcessScriptVariables: invalid value");
}
if (driver_factory->SetProcessScriptVariables(mode)) {
result = RewriteOptions::kOptionOk;
} else {
return const_cast<char*>(
"pagespeed ProcessScriptVariables: can only be set once");
}
} else {
bool ok = driver_factory->caches()->CreateShmMetadataCache(
args[1].as_string(), kb, &msg);
result = ok ? kOptionOk : kOptionValueInvalid;
return const_cast<char*>(
"ProcessScriptVariables is only allowed at the top level");
}
} else {
result = ParseAndSetOptionFromName2(directive, args[1], args[2],
&msg, handler);
result = ParseAndSetOptionFromName1(directive, arg, &msg, handler);
if (result == RewriteOptions::kOptionNameUnknown) {
result = driver_factory->ParseAndSetOption1(
directive,
arg,
scope >= RewriteOptions::kLegacyProcessScope,
&msg,
handler);
}
}
} else if (n_args == 3) {
result = ParseAndSetOptionFromName2(directive, args[1], args[2],
&msg, handler);
if (result == RewriteOptions::kOptionNameUnknown) {
result = driver_factory->ParseAndSetOption2(
directive,
args[1],
args[2],
scope >= RewriteOptions::kLegacyProcessScope,
&msg,
handler);
}
} else if (n_args == 4) {
result = ParseAndSetOptionFromName3(
directive, args[1], args[2], args[3], &msg, handler);
} else {
return "unknown option";
result = RewriteOptions::kOptionNameUnknown;
}
switch (result) {
case RewriteOptions::kOptionOk:
return NGX_CONF_OK;
case RewriteOptions::kOptionNameUnknown:
return "unknown option";
return ps_error_string_for_option(
pool, directive, "not recognized or too many arguments");
case RewriteOptions::kOptionValueInvalid: {
GoogleString full_directive = "\"";
GoogleString full_directive;
for (int i = 0 ; i < n_args ; i++) {
StrAppend(&full_directive, i == 0 ? "" : " ", args[i]);
}
StrAppend(&full_directive, "\": ", msg);
char* s = ngx_psol::string_piece_to_pool_string(pool, full_directive);
if (s == NULL) {
return "failed to allocate memory";
}
return s;
return ps_error_string_for_option(pool, full_directive, msg);
}
}
@@ -239,8 +464,84 @@ NgxRewriteOptions::ParseAndSetOptions(
return NULL;
}
// Execute all entries in the script_lines vector, and hand the result off to
// ParseAndSetOptions to obtain the final option values.
bool NgxRewriteOptions::ExecuteScriptVariables(
ngx_http_request_t* r, MessageHandler* handler,
NgxRewriteDriverFactory* driver_factory) {
bool script_error = false;
if (script_lines_.size() > 0) {
std::vector<RefCountedPtr<ScriptLine> >::iterator it;
for (it = script_lines_.begin() ; it != script_lines_.end(); ++it) {
ScriptLine* script_line = it->get();
StringPiece args[NGX_PAGESPEED_MAX_ARGS];
std::vector<ScriptArgIndex*>::iterator cs_it;
int i;
for (i = 0; i < script_line->n_args(); i++) {
args[i] = script_line->args()[i];
}
for (cs_it = script_line->data().begin();
cs_it != script_line->data().end(); cs_it++) {
ngx_http_script_compile_t* script;
ngx_array_t* values;
ngx_array_t* lengths;
ngx_str_t value;
script = (*cs_it)->script();
lengths = *script->lengths;
values = *script->values;
if (ngx_http_script_run(r, &value, lengths->elts, 0, values->elts)
== NULL) {
handler->Message(kError, "ngx_http_script_run error");
script_error = true;
break;
} else {
args[(*cs_it)->index()] = str_to_string_piece(value);
}
}
const char* status = ParseAndSetOptions(args, script_line->n_args(),
r->pool, handler, driver_factory, script_line->scope(), NULL /*cf*/,
ProcessScriptVariablesMode::kOff);
if (status != NULL) {
script_error = true;
handler->Message(kWarning,
"Error setting option value from script: '%s'", status);
break;
}
}
}
if (script_error) {
handler->Message(kWarning,
"Script error(s) in configuration, disabling optimization");
set_enabled(RewriteOptions::kEnabledOff);
return false;
}
return true;
}
void NgxRewriteOptions::CopyScriptLinesTo(
NgxRewriteOptions* destination) const {
destination->script_lines_ = script_lines_;
}
void NgxRewriteOptions::AppendScriptLinesTo(
NgxRewriteOptions* destination) const {
destination->script_lines_.insert(destination->script_lines_.end(),
script_lines_.begin(), script_lines_.end());
}
NgxRewriteOptions* NgxRewriteOptions::Clone() const {
NgxRewriteOptions* options = new NgxRewriteOptions();
NgxRewriteOptions* options = new NgxRewriteOptions(
StrCat("cloned from ", description()), thread_system());
this->CopyScriptLinesTo(options);
options->Merge(*this);
return options;
}
+148 -24
View File
@@ -1,20 +1,23 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: jefftk@google.com (Jeff Kaufman)
// Manage configuration for pagespeed. Compare to ApacheConfig.
@@ -27,20 +30,92 @@ extern "C" {
#include <ngx_http.h>
}
#include <vector>
#include "ngx_rewrite_driver_factory.h"
#include "net/instaweb/rewriter/public/rewrite_options.h"
#include "net/instaweb/system/public/system_rewrite_options.h"
#include "pagespeed/kernel/base/message_handler.h"
#include "pagespeed/kernel/base/ref_counted_ptr.h"
#include "pagespeed/kernel/base/stl_util.h" // for STLDeleteElements
#include "pagespeed/system/system_rewrite_options.h"
#define NGX_PAGESPEED_MAX_ARGS 10
namespace net_instaweb {
class NgxRewriteDriverFactory;
class ScriptArgIndex {
public:
explicit ScriptArgIndex(ngx_http_script_compile_t* script, int index)
: script_(script), index_(index) {
CHECK(script != NULL);
CHECK(index > 0 && index < NGX_PAGESPEED_MAX_ARGS);
}
virtual ~ScriptArgIndex() {}
ngx_http_script_compile_t* script() { return script_; }
int index() { return index_; }
private:
// Not owned.
ngx_http_script_compile_t* script_;
int index_;
};
// Refcounted, because the ScriptArgIndexes inside data_ can be shared between
// different rewriteoptions.
class ScriptLine : public RefCounted<ScriptLine> {
public:
explicit ScriptLine(StringPiece* args, int n_args,
RewriteOptions::OptionScope scope)
: n_args_(n_args),
scope_(scope) {
for (int i = 0; i < n_args; i++) {
args_[i] = args[i];
}
}
virtual ~ScriptLine() {
STLDeleteElements(&data_);
data_.clear();
}
void AddScriptAndArgIndex(ngx_http_script_compile_t* script,
int script_index) {
CHECK(script != NULL);
CHECK(script_index < NGX_PAGESPEED_MAX_ARGS);
data_.push_back(new ScriptArgIndex(script, script_index));
}
int n_args() { return n_args_;}
StringPiece* args() { return args_;}
RewriteOptions::OptionScope scope() { return scope_; }
std::vector<ScriptArgIndex*>& data() {
return data_;
}
private:
StringPiece args_[NGX_PAGESPEED_MAX_ARGS];
int n_args_;
RewriteOptions::OptionScope scope_;
std::vector<ScriptArgIndex*> data_;
DISALLOW_COPY_AND_ASSIGN(ScriptLine);
};
class NgxRewriteOptions : public SystemRewriteOptions {
public:
// See rewrite_options::Initialize and ::Terminate
static void Initialize();
static void Terminate();
NgxRewriteOptions();
NgxRewriteOptions(const StringPiece& description,
ThreadSystem* thread_system);
explicit NgxRewriteOptions(ThreadSystem* thread_system);
virtual ~NgxRewriteOptions() { }
// args is an array of n_args StringPieces together representing a directive.
@@ -54,9 +129,19 @@ class NgxRewriteOptions : public SystemRewriteOptions {
// on failure.
//
// pool is a memory pool for allocating error strings.
// cf is only required when compile_scripts is true
// when compile_scripts is true, the rewrite_options will be prepared
// for replacing any script $variables encountered in args. when false,
// script variables will be substituted using the prepared rewrite options.
const char* ParseAndSetOptions(
StringPiece* args, int n_args, ngx_pool_t* pool, MessageHandler* handler,
NgxRewriteDriverFactory* driver_factory, OptionScope scope,
ngx_conf_t* cf, ProcessScriptVariablesMode script_mode);
bool ExecuteScriptVariables(
ngx_http_request_t* r, MessageHandler* handler,
NgxRewriteDriverFactory* driver_factory);
void CopyScriptLinesTo(NgxRewriteOptions* destination) const;
void AppendScriptLinesTo(NgxRewriteOptions* destination) const;
// Make an identical copy of these options and return it.
virtual NgxRewriteOptions* Clone() const;
@@ -66,6 +151,30 @@ class NgxRewriteOptions : public SystemRewriteOptions {
static const NgxRewriteOptions* DynamicCast(const RewriteOptions* instance);
static NgxRewriteOptions* DynamicCast(RewriteOptions* instance);
const GoogleString& statistics_path() const {
return statistics_path_.value();
}
const GoogleString& global_statistics_path() const {
return global_statistics_path_.value();
}
const GoogleString& console_path() const {
return console_path_.value();
}
const GoogleString& messages_path() const {
return messages_path_.value();
}
const GoogleString& admin_path() const {
return admin_path_.value();
}
const GoogleString& global_admin_path() const {
return global_admin_path_.value();
}
const std::vector<RefCountedPtr<ScriptLine> >& script_lines() const {
return script_lines_;
}
const bool& clear_inherited_scripts() const {
return clear_inherited_scripts_;
}
private:
// Helper methods for ParseAndSetOptions(). Each can:
@@ -85,9 +194,8 @@ class NgxRewriteOptions : public SystemRewriteOptions {
OptionSettingResult ParseAndSetOptions0(
StringPiece directive, GoogleString* msg, MessageHandler* handler);
// These are called via RewriteOptions::ParseAndSetOptionFromName[123]
virtual OptionSettingResult ParseAndSetOptionFromEnum1(
OptionEnum name, StringPiece arg,
virtual OptionSettingResult ParseAndSetOptionFromName1(
StringPiece name, StringPiece arg,
GoogleString* msg, MessageHandler* handler);
// We may want to override 2- and 3-argument versions as well in the future,
@@ -102,21 +210,37 @@ class NgxRewriteOptions : public SystemRewriteOptions {
static Properties* ngx_properties_;
static void AddProperties();
void Init();
void InitializeSignaturesAndDefaults();
// Add an option to ngx_properties_
template<class RewriteOptionsSubclass, class OptionClass>
template<class OptionClass>
static void add_ngx_option(typename OptionClass::ValueType default_value,
OptionClass RewriteOptionsSubclass::*offset,
OptionClass NgxRewriteOptions::*offset,
const char* id,
OptionEnum option_enum) {
AddProperty(default_value, offset, id, option_enum, ngx_properties_);
StringPiece option_name,
OptionScope scope,
const char* help,
bool safe_to_print) {
AddProperty(default_value, offset, id, option_name, scope, help,
safe_to_print, ngx_properties_);
}
Option<GoogleString> statistics_path_;
Option<GoogleString> global_statistics_path_;
Option<GoogleString> console_path_;
Option<GoogleString> messages_path_;
Option<GoogleString> admin_path_;
Option<GoogleString> global_admin_path_;
bool clear_inherited_scripts_;
std::vector<RefCountedPtr<ScriptLine> > script_lines_;
// Helper for ParseAndSetOptions. Returns whether the two directives equal,
// ignoring case.
bool IsDirective(StringPiece config_directive, StringPiece compare_directive);
// Returns a given option's scope.
RewriteOptions::OptionScope GetOptionScope(StringPiece option_name);
// TODO(jefftk): support fetch proxy in server and location blocks.
DISALLOW_COPY_AND_ASSIGN(NgxRewriteOptions);
+74 -113
View File
@@ -1,140 +1,101 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: jefftk@google.com (Jeff Kaufman)
#include "ngx_server_context.h"
#include "ngx_request_context.h"
#include "ngx_rewrite_options.h"
extern "C" {
#include <ngx_http.h>
}
#include "ngx_pagespeed.h"
#include "ngx_message_handler.h"
#include "ngx_rewrite_driver_factory.h"
#include "net/instaweb/apache/add_headers_fetcher.h"
#include "net/instaweb/apache/loopback_route_fetcher.h"
#include "ngx_rewrite_options.h"
#include "net/instaweb/rewriter/public/rewrite_driver.h"
#include "net/instaweb/rewriter/public/rewrite_stats.h"
#include "net/instaweb/system/public/system_caches.h"
#include "net/instaweb/util/public/shared_mem_statistics.h"
#include "net/instaweb/util/public/split_statistics.h"
#include "net/instaweb/util/public/statistics.h"
#include "pagespeed/system/add_headers_fetcher.h"
#include "pagespeed/system/loopback_route_fetcher.h"
#include "pagespeed/system/system_request_context.h"
namespace net_instaweb {
const char kCacheFlushCount[] = "cache_flush_count";
const char kCacheFlushTimestampMs[] = "cache_flush_timestamp_ms";
// Statistics histogram names.
const char kHtmlRewriteTimeUsHistogram[] = "Html Time us Histogram";
NgxServerContext::NgxServerContext(NgxRewriteDriverFactory* factory)
: SystemServerContext(factory),
ngx_factory_(factory),
initialized_(false) {
NgxServerContext::NgxServerContext(
NgxRewriteDriverFactory* factory, StringPiece hostname, int port)
: SystemServerContext(factory, hostname, port),
ngx_http2_variable_index_(NGX_ERROR) {
}
NgxServerContext::~NgxServerContext() {
}
NgxServerContext::~NgxServerContext() { }
NgxRewriteOptions* NgxServerContext::config() {
return NgxRewriteOptions::DynamicCast(global_options());
}
void NgxServerContext::ChildInit() {
DCHECK(!initialized_);
if (!initialized_) {
initialized_ = true;
set_lock_manager(ngx_factory_->caches()->GetLockManager(config()));
SystemRequestContext* NgxServerContext::NewRequestContext(
ngx_http_request_t* r) {
// Based on ngx_http_variable_server_port.
bool port_set = false;
int local_port = 0;
#if (NGX_HAVE_INET6)
if (r->connection->local_sockaddr->sa_family == AF_INET6) {
local_port = ntohs(reinterpret_cast<struct sockaddr_in6*>(
r->connection->local_sockaddr)->sin6_port);
port_set = true;
}
#endif
if (!port_set) {
local_port = ntohs(reinterpret_cast<struct sockaddr_in*>(
r->connection->local_sockaddr)->sin_port);
}
if (split_statistics_.get() != NULL) {
// Readjust the SHM stuff for the new process
local_statistics_->Init(false, message_handler());
ngx_str_t local_ip;
u_char addr[NGX_SOCKADDR_STRLEN];
local_ip.len = NGX_SOCKADDR_STRLEN;
local_ip.data = addr;
ngx_int_t rc = ngx_connection_local_sockaddr(r->connection, &local_ip, 0);
if (rc != NGX_OK) {
local_ip.len = 0;
}
// Create local stats for the ServerContext, and fill in its
// statistics() and rewrite_stats() using them; if we didn't do this here
// they would get set to the factory's by the InitServerContext call
// below.
set_statistics(split_statistics_.get());
local_rewrite_stats_.reset(new RewriteStats(
split_statistics_.get(), ngx_factory_->thread_system(),
ngx_factory_->timer()));
set_rewrite_stats(local_rewrite_stats_.get());
SystemRequestContext* ctx = new SystemRequestContext(
thread_system()->NewMutex(), timer(),
ps_determine_host(r), local_port, str_to_string_piece(local_ip));
// See if http2 is in use.
if (ngx_http2_variable_index_ >= 0) {
ngx_http_variable_value_t* val =
ngx_http_get_indexed_variable(r, ngx_http2_variable_index_);
if (val != NULL && val->valid) {
StringPiece str_val(reinterpret_cast<char*>(val->data), val->len);
if (str_val == "h2" || str_val == "h2c") {
ctx->set_using_http2(true);
}
}
ngx_factory_->InitServerContext(this);
// TODO(oschaaf): in mod_pagespeed, the ServerContext owns
// the fetchers, and sets up the UrlAsyncFetcherStats here
}
}
void NgxServerContext::CreateLocalStatistics(
Statistics* global_statistics) {
local_statistics_ =
ngx_factory_->AllocateAndInitSharedMemStatistics(
hostname_identifier(),
config()->statistics_logging_enabled(),
config()->statistics_logging_interval_ms(),
config()->statistics_logging_file());
split_statistics_.reset(new SplitStatistics(
ngx_factory_->thread_system(), local_statistics_, global_statistics));
// local_statistics_ was ::InitStat'd by AllocateAndInitSharedMemStatistics,
// but we need to take care of split_statistics_.
NgxRewriteDriverFactory::InitStats(split_statistics_.get());
}
void NgxServerContext::InitStats(Statistics* statistics) {
// TODO(oschaaf): we need to port the cache flush mechanism
statistics->AddVariable(kCacheFlushCount);
statistics->AddVariable(kCacheFlushTimestampMs);
Histogram* html_rewrite_time_us_histogram =
statistics->AddHistogram(kHtmlRewriteTimeUsHistogram);
// We set the boundary at 2 seconds which is about 2 orders of magnitude
// worse than anything we have reasonably seen, to make sure we don't
// cut off actual samples.
html_rewrite_time_us_histogram->SetMaxValue(2 * Timer::kSecondUs);
// TODO(oschaaf): Once the ServerContext owns the fetchers,
// initialise UrlAsyncFetcherStats here
}
void NgxServerContext::ApplySessionFetchers(
const RequestContextPtr& request, RewriteDriver* driver) {
const NgxRewriteOptions* conf = NgxRewriteOptions::DynamicCast(
driver->options());
CHECK(conf != NULL);
NgxRequestContext* ngx_request = NgxRequestContext::DynamicCast(
request.get());
if (ngx_request == NULL) {
return; // decoding_driver has a null RequestContext.
}
// Note that these fetchers are applied in the opposite order of how they are
// added
// TODO(oschaaf): in mod_pagespeed, LoopbackRouteFetcher is not added when
// one of these is set: disable_loopback_routing, slurping_enabled, or
// test_proxy.
return ctx;
}
// Note the port here is our port, not from the request, since
// LoopbackRouteFetcher may decide we should be talking to ourselves.
driver->SetSessionFetcher(new LoopbackRouteFetcher(
driver->options(), ngx_request->local_ip(),
ngx_request->local_port(), driver->async_fetcher()));
if (driver->options()->num_custom_fetch_headers() > 0) {
driver->SetSessionFetcher(new AddHeadersFetcher(driver->options(),
driver->async_fetcher()));
}
GoogleString NgxServerContext::FormatOption(StringPiece option_name,
StringPiece args) {
return StrCat("pagespeed ", option_name, " ", args, ";");
}
} // namespace net_instaweb
+47 -45
View File
@@ -1,76 +1,78 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: jefftk@google.com (Jeff Kaufman)
// Manage pagespeed state across requests. Compare to ApacheResourceManager.
#ifndef NGX_SERVER_CONTEXT_H_
#define NGX_SERVER_CONTEXT_H_
#include "net/instaweb/system/public/system_server_context.h"
#include "ngx_message_handler.h"
#include "pagespeed/system/system_server_context.h"
extern "C" {
#include <ngx_http.h>
}
namespace net_instaweb {
class NgxRewriteDriverFactory;
class NgxRewriteOptions;
class RewriteStats;
class SharedMemStatistics;
class Statistics;
class SystemRequestContext;
class NgxServerContext : public SystemServerContext {
public:
explicit NgxServerContext(NgxRewriteDriverFactory* factory);
NgxServerContext(
NgxRewriteDriverFactory* factory, StringPiece hostname, int port);
virtual ~NgxServerContext();
// We expect to use ProxyFetch with HTML.
virtual bool ProxiesHtml() const { return true; }
// We don't allow ProxyFetch to fetch HTML via MapProxyDomain. We will call
// set_trusted_input() on any ProxyFetches we use to transform internal HTML.
virtual bool ProxiesHtml() const { return false; }
// Call only when you need an NgxRewriteOptions. If you don't need
// nginx-specific behavior, call global_options() instead which doesn't
// downcast.
NgxRewriteOptions* config();
// Should be called after the child process is forked.
void ChildInit();
// Initialize this ServerContext to have its own statistics domain.
// Must be called after global_statistics has been created and had
// ::Initialize called on it.
void CreateLocalStatistics(Statistics* global_statistics);
static void InitStats(Statistics* statistics);
virtual void ApplySessionFetchers(const RequestContextPtr& req,
RewriteDriver* driver);
bool initialized() const { return initialized_; }
GoogleString hostname_identifier() { return hostname_identifier_; }
void set_hostname_identifier(GoogleString x) { hostname_identifier_ = x; }
NgxRewriteDriverFactory* ngx_rewrite_driver_factory() { return ngx_factory_; }
SystemRequestContext* NewRequestContext(ngx_http_request_t* r);
NgxMessageHandler* ngx_message_handler() {
return dynamic_cast<NgxMessageHandler*>(message_handler());
}
virtual GoogleString FormatOption(StringPiece option_name, StringPiece args);
void set_ngx_http2_variable_index(ngx_int_t idx) {
ngx_http2_variable_index_ = idx;
}
ngx_int_t ngx_http2_variable_index() const {
return ngx_http2_variable_index_;
}
private:
NgxRewriteDriverFactory* ngx_factory_;
// hostname_identifier_ is used to distinguish the name of shared memory
// segments associated with this ServerContext
GoogleString hostname_identifier_;
bool initialized_;
// Non-NULL if we have per-vhost stats.
scoped_ptr<Statistics> split_statistics_;
// May be NULL. Owned by *split_statistics_.
SharedMemStatistics* local_statistics_;
// These are non-NULL if we have per-vhost stats.
scoped_ptr<RewriteStats> local_rewrite_stats_;
// what index the "http2" var is, or NGX_ERROR.
ngx_int_t ngx_http2_variable_index_;
DISALLOW_COPY_AND_ASSIGN(NgxServerContext);
};
-46
View File
@@ -1,46 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Author: jefftk@google.com (Jeff Kaufman)
#include "ngx_thread_system.h"
#include "apr_thread_proc.h"
namespace net_instaweb {
class Timer;
NgxThreadSystem::NgxThreadSystem() : may_start_threads_(false) {}
NgxThreadSystem::~NgxThreadSystem() {}
void NgxThreadSystem::PermitThreadStarting() {
CHECK(!may_start_threads_);
may_start_threads_ = true;
}
void NgxThreadSystem::BeforeThreadRunHook() {
// We disable all signals here, since the nginx worker process is expecting to
// catch them and pagespeed doesn't use signals.
apr_setup_signal_thread();
// If this fails you can get a backtrace from gdb by setting a breakpoint on
// "pthread_create".
CHECK(may_start_threads_);
}
} // namespace net_instaweb
-56
View File
@@ -1,56 +0,0 @@
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Author: jefftk@google.com (Jeff Kaufman)
//
// See ApacheThreadSystem.
//
//
#ifndef NGX_THREAD_SYSTEM_H_
#define NGX_THREAD_SYSTEM_H_
#include "base/logging.h"
#include "net/instaweb/util/public/basictypes.h"
#include "net/instaweb/util/public/pthread_thread_system.h"
namespace net_instaweb {
class Timer;
class NgxThreadSystem : public PthreadThreadSystem {
public:
NgxThreadSystem();
virtual ~NgxThreadSystem();
// In nginx we may only start threads after forking a worker process. In
// order to enforce this, we call PermitThreadStarting() in the worker process
// right after forking, and CHECK-fail if something tries to start a thread
// before then.
void PermitThreadStarting();
protected:
virtual void BeforeThreadRunHook();
private:
bool may_start_threads_;
DISALLOW_COPY_AND_ASSIGN(NgxThreadSystem);
};
} // namespace net_instaweb
#endif // NGX_THREAD_SYSTEM_H_
+135 -157
View File
@@ -1,20 +1,23 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: x.dinic@gmail.com (Junmin Xiong)
extern "C" {
#include <ngx_http.h>
@@ -31,22 +34,22 @@ extern "C" {
#include <map>
#include <set>
#include "net/instaweb/util/public/basictypes.h"
#include "net/instaweb/http/public/async_fetch.h"
#include "net/instaweb/http/public/inflating_fetch.h"
#include "net/instaweb/http/public/request_headers.h"
#include "net/instaweb/http/public/response_headers.h"
#include "net/instaweb/http/public/response_headers_parser.h"
#include "net/instaweb/public/version.h"
#include "net/instaweb/util/public/condvar.h"
#include "net/instaweb/util/public/message_handler.h"
#include "net/instaweb/util/public/pool.h"
#include "net/instaweb/util/public/pool_element.h"
#include "net/instaweb/util/public/statistics.h"
#include "net/instaweb/util/public/string_util.h"
#include "net/instaweb/util/public/thread_system.h"
#include "net/instaweb/util/public/timer.h"
#include "net/instaweb/util/public/writer.h"
#include "pagespeed/kernel/base/basictypes.h"
#include "pagespeed/kernel/base/condvar.h"
#include "pagespeed/kernel/base/message_handler.h"
#include "pagespeed/kernel/base/pool.h"
#include "pagespeed/kernel/base/pool_element.h"
#include "pagespeed/kernel/base/statistics.h"
#include "pagespeed/kernel/base/string_util.h"
#include "pagespeed/kernel/base/thread_system.h"
#include "pagespeed/kernel/base/timer.h"
#include "pagespeed/kernel/base/writer.h"
#include "pagespeed/kernel/http/request_headers.h"
#include "pagespeed/kernel/http/response_headers.h"
#include "pagespeed/kernel/http/response_headers_parser.h"
namespace net_instaweb {
@@ -55,6 +58,7 @@ namespace net_instaweb {
ngx_msec_t resolver_timeout,
ngx_msec_t fetch_timeout,
ngx_resolver_t* resolver,
int max_keepalive_requests,
ThreadSystem* thread_system,
MessageHandler* handler)
: fetchers_count_(0),
@@ -63,23 +67,30 @@ namespace net_instaweb {
byte_count_(0),
thread_system_(thread_system),
message_handler_(handler),
mutex_(NULL) {
mutex_(NULL),
max_keepalive_requests_(max_keepalive_requests),
event_connection_(NULL) {
resolver_timeout_ = resolver_timeout;
fetch_timeout_ = fetch_timeout;
ngx_memzero(&url_, sizeof(url_));
ngx_memzero(&proxy_, sizeof(proxy_));
if (proxy != NULL && *proxy != '\0') {
url_.url.data = reinterpret_cast<u_char*>(const_cast<char*>(proxy));
url_.url.len = ngx_strlen(proxy);
proxy_.url.data = reinterpret_cast<u_char*>(const_cast<char*>(proxy));
proxy_.url.len = ngx_strlen(proxy);
}
mutex_ = thread_system_->NewMutex();
log_ = log;
pool_ = NULL;
command_connection_ = NULL;
pipe_fd_ = -1;
resolver_ = resolver;
// If init fails, set shutdown_ so no fetches will be attempted.
if (!Init(const_cast<ngx_cycle_t*>(ngx_cycle))) {
shutdown_ = true;
message_handler_->Message(
kError, "NgxUrlAsyncFetcher failed to init, fetching disabled.");
}
}
NgxUrlAsyncFetcher::~NgxUrlAsyncFetcher() {
DCHECK(shutdown_) << "Shut down before destructing NgxUrlAsyncFetcher.";
message_handler_->Message(
kInfo,
"Destruct NgxUrlAsyncFetcher with [%d] active fetchers",
@@ -87,25 +98,48 @@ namespace net_instaweb {
CancelActiveFetches();
active_fetches_.DeleteAll();
NgxConnection::Terminate();
if (pool_ != NULL) {
ngx_destroy_pool(pool_);
pool_ = NULL;
}
if (command_connection_ != NULL) {
ngx_close_connection(command_connection_);
command_connection_ = NULL;
}
if (pipe_fd_ != -1) {
close(pipe_fd_);
pipe_fd_ = -1;
}
if (mutex_ != NULL) {
delete mutex_;
mutex_ = NULL;
}
}
bool NgxUrlAsyncFetcher::ParseUrl(ngx_url_t* url, ngx_pool_t* pool) {
size_t scheme_offset;
u_short port;
if (ngx_strncasecmp(url->url.data, reinterpret_cast<u_char*>(
const_cast<char*>("http://")), 7) == 0) {
scheme_offset = 7;
port = 80;
} else if (ngx_strncasecmp(url->url.data, reinterpret_cast<u_char*>(
const_cast<char*>("https://")), 8) == 0) {
scheme_offset = 8;
port = 443;
} else {
scheme_offset = 0;
port = 80;
}
url->url.data += scheme_offset;
url->url.len -= scheme_offset;
url->default_port = port;
// See: http://lxr.evanmiller.org/http/source/core/ngx_inet.c#L875
url->no_resolve = 0;
url->uri_part = 1;
if (ngx_parse_url(pool, url) == NGX_OK) {
return true;
}
return false;
}
// If there are still active requests, cancel them.
void NgxUrlAsyncFetcher::CancelActiveFetches() {
// TODO(oschaaf): this seems tricky, this may end up calling
@@ -120,9 +154,13 @@ namespace net_instaweb {
// Create the pool for fetcher, create the pipe, add the read event for main
// thread. It should be called in the worker process.
bool NgxUrlAsyncFetcher::Init() {
log_ = ngx_cycle->log;
bool NgxUrlAsyncFetcher::Init(ngx_cycle_t* cycle) {
log_ = cycle->log;
CHECK(event_connection_ == NULL) << "event connection already set";
event_connection_ = new NgxEventConnection(ReadCallback);
if (!event_connection_->Init(cycle)) {
return false;
}
if (pool_ == NULL) {
pool_ = ngx_create_pool(4096, log_);
if (pool_ == NULL) {
@@ -132,58 +170,44 @@ namespace net_instaweb {
}
}
int pipe_fds[2];
int rc = pipe(pipe_fds);
if (rc != 0) {
ngx_log_error(NGX_LOG_ERR, log_, 0, "pipe() failed");
return false;
}
if (ngx_nonblocking(pipe_fds[0]) == -1) {
ngx_log_error(NGX_LOG_ERR, log_, 0, "nonblocking pipe[0] failed");
return false;
}
if (ngx_nonblocking(pipe_fds[1]) == -1) {
ngx_log_error(NGX_LOG_ERR, log_, 0, "nonblocking pipe[1] failed");
return false;
}
pipe_fd_ = pipe_fds[1];
command_connection_ = ngx_get_connection(pipe_fds[0], log_);
if (command_connection_ == NULL) {
close(pipe_fds[1]);
close(pipe_fds[0]);
pipe_fd_ = -1;
return false;
}
command_connection_->recv = ngx_recv;
command_connection_->send = ngx_send;
command_connection_->recv_chain = ngx_recv_chain;
command_connection_->send_chain = ngx_send_chain;
command_connection_->log = log_;
command_connection_->read->log = log_;
command_connection_->write->log = log_;
command_connection_->data = this;
command_connection_->read->handler = CommandHandler;
ngx_add_event(command_connection_->read, NGX_READ_EVENT, 0);
if (url_.url.len == 0) {
if (proxy_.url.len == 0) {
return true;
}
// TODO(oschaaf): shouldn't we do this earlier? Do we need to clean
// up when parsing the url failed?
if (ngx_parse_url(pool_, &url_) != NGX_OK) {
if (!ParseUrl(&proxy_, pool_)) {
ngx_log_error(NGX_LOG_ERR, log_, 0,
"NgxUrlAsyncFetcher::Init parse proxy[%V] failed", &url_.url);
"NgxUrlAsyncFetcher::Init parse proxy[%V] failed", &proxy_.url);
return false;
}
return true;
}
void NgxUrlAsyncFetcher::ShutDown() {
shutdown_ = true;
SendCmd('S');
shutdown_ = true;
if (!pending_fetches_.empty()) {
for (Pool<NgxFetch>::iterator p = pending_fetches_.begin(),
e = pending_fetches_.end(); p != e; p++) {
NgxFetch* fetch = *p;
fetch->CallbackDone(false);
}
pending_fetches_.DeleteAll();
}
if (!active_fetches_.empty()) {
for (Pool<NgxFetch>::iterator p = active_fetches_.begin(),
e = active_fetches_.end(); p != e; p++) {
NgxFetch* fetch = *p;
fetch->CallbackDone(false);
}
active_fetches_.Clear();
}
if (event_connection_ != NULL) {
event_connection_->Shutdown();
delete event_connection_;
event_connection_ = NULL;
}
}
// It's called in the rewrite thread. All the fetches are started at
@@ -191,92 +215,46 @@ namespace net_instaweb {
void NgxUrlAsyncFetcher::Fetch(const GoogleString& url,
MessageHandler* message_handler,
AsyncFetch* async_fetch) {
async_fetch = EnableInflation(async_fetch, NULL);
// Don't accept new fetches when shut down. This flow is also entered when
// we did not initialize properly in ::Init().
if (shutdown_) {
async_fetch->Done(false);
return;
}
async_fetch = EnableInflation(async_fetch);
NgxFetch* fetch = new NgxFetch(url, async_fetch,
message_handler, fetch_timeout_, log_);
message_handler, log_);
ScopedMutex lock(mutex_);
pending_fetches_.Add(fetch);
SendCmd('F');
}
// send command to nginx main thread
// 'F' : start a fetch
// 'S' : shutdown the fetcher
bool NgxUrlAsyncFetcher::SendCmd(const char command) {
int rc;
while (true) {
rc = write(pipe_fd_, &command, 1);
if (rc == 1) {
return true;
} else if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
// TODO(junmin): It's rare. But it need be fixed.
} else {
return false;
}
}
return true;
// TODO(oschaaf): thread safety on written vs shutdown.
// It is possible that shutdown() is called after writing an event? In that
// case, this could (rarely) fail when it shouldn't.
bool written = event_connection_->WriteEvent(this);
CHECK(written || shutdown_) << "NgxUrlAsyncFetcher: event write failure";
}
// This is the read event which is called in the main thread.
// It will do the real work. Add the work event and start the fetch.
void NgxUrlAsyncFetcher::CommandHandler(ngx_event_t *cmdev) {
char command;
int rc;
ngx_connection_t* c = static_cast<ngx_connection_t*>(cmdev->data);
NgxUrlAsyncFetcher* fetcher = static_cast<NgxUrlAsyncFetcher*>(c->data);
do {
rc = read(c->fd, &command, 1);
} while (rc == -1 && errno == EINTR);
void NgxUrlAsyncFetcher::ReadCallback(const ps_event_data& data) {
std::vector<NgxFetch*> to_start;
NgxUrlAsyncFetcher* fetcher = reinterpret_cast<NgxUrlAsyncFetcher*>(
data.sender);
CHECK(rc == -1 || rc == 0 || rc == 1);
fetcher->mutex_->Lock();
fetcher->completed_fetches_.DeleteAll();
if (rc == -1 || rc == 0) {
// EAGAIN
return;
for (Pool<NgxFetch>::iterator p = fetcher->pending_fetches_.begin(),
e = fetcher->pending_fetches_.end(); p != e; p++) {
NgxFetch* fetch = *p;
to_start.push_back(fetch);
}
std::vector<NgxFetch*> to_start;
fetcher->pending_fetches_.Clear();
fetcher->mutex_->Unlock();
switch (command) {
// All the new fetches are appended in the pending_fetches.
// Start all these fetches.
case 'F':
fetcher->mutex_->Lock();
fetcher->completed_fetches_.DeleteAll();
for (Pool<NgxFetch>::iterator p = fetcher->pending_fetches_.begin(),
e = fetcher->pending_fetches_.end(); p != e; p++) {
NgxFetch* fetch = *p;
to_start.push_back(fetch);
}
fetcher->pending_fetches_.Clear();
fetcher->mutex_->Unlock();
for (size_t i = 0; i < to_start.size(); i++) {
fetcher->StartFetch(to_start[i]);
}
CHECK(ngx_handle_read_event(cmdev, 0) == NGX_OK);
break;
// Shutdown all the fetches.
case 'S':
if (!fetcher->pending_fetches_.empty()) {
fetcher->pending_fetches_.DeleteAll();
}
if (!fetcher->active_fetches_.empty()) {
for (Pool<NgxFetch>::iterator p = fetcher->active_fetches_.begin(),
e = fetcher->active_fetches_.end(); p != e; p++) {
NgxFetch* fetch = *p;
fetch->CallbackDone(false);
}
fetcher->active_fetches_.Clear();
}
CHECK(ngx_del_event(cmdev, NGX_READ_EVENT, 0) == NGX_OK);
break;
default:
break;
for (size_t i = 0; i < to_start.size(); i++) {
fetcher->StartFetch(to_start[i]);
}
return;
+36 -28
View File
@@ -1,20 +1,23 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Author: x.dinic@gmail.com(Junmin Xiong)
//
// Fetch the resources asynchronously in Nginx. The fetcher is called in
// the rewrite thread.
@@ -33,11 +36,14 @@ extern "C" {
}
#include <vector>
#include "net/instaweb/util/public/basictypes.h"
#include "net/instaweb/util/public/pool.h"
#include "net/instaweb/util/public/string.h"
#include "net/instaweb/util/public/thread_system.h"
#include "net/instaweb/http/public/url_pollable_async_fetcher.h"
#include "ngx_event_connection.h"
#include "net/instaweb/http/public/url_async_fetcher.h"
#include "pagespeed/kernel/base/basictypes.h"
#include "pagespeed/kernel/base/pool.h"
#include "pagespeed/kernel/base/string.h"
#include "pagespeed/kernel/base/thread_system.h"
namespace net_instaweb {
@@ -53,27 +59,27 @@ class NgxUrlAsyncFetcher : public UrlAsyncFetcher {
NgxUrlAsyncFetcher(
const char* proxy, ngx_log_t* log, ngx_msec_t resolver_timeout,
ngx_msec_t fetch_timeout, ngx_resolver_t* resolver,
ThreadSystem* thread_system, MessageHandler* handler);
int max_keepalive_requests, ThreadSystem* thread_system,
MessageHandler* handler);
~NgxUrlAsyncFetcher();
// It should be called in the module init_process callback function. Do some
// intializations which can't be done in the master process
bool Init();
bool Init(ngx_cycle_t* cycle);
// shutdown all the fetches.
virtual void ShutDown();
// the read handler in the main thread
static void ReadCallback(const ps_event_data& data);
virtual bool SupportsHttps() const { return false; }
virtual void Fetch(const GoogleString& url,
MessageHandler* message_handler,
AsyncFetch* callback);
// send the command from the current thread to main thread
bool SendCmd(const char command);
// the read handler in the main thread
static void CommandHandler(ngx_event_t* cmdev);
bool StartFetch(NgxFetch* fetch);
// Remove the completed fetch from the active fetch set, and put it into a
@@ -115,13 +121,14 @@ class NgxUrlAsyncFetcher : public UrlAsyncFetcher {
private:
static void TimeoutHandler(ngx_event_t* tev);
static bool ParseUrl(ngx_url_t* url, ngx_pool_t* pool);
friend class NgxFetch;
NgxFetchPool active_fetches_;
// Add the pending task to this list
NgxFetchPool pending_fetches_;
NgxFetchPool completed_fetches_;
ngx_url_t url_;
ngx_url_t proxy_;
int fetchers_count_;
bool shutdown_;
@@ -135,12 +142,13 @@ class NgxUrlAsyncFetcher : public UrlAsyncFetcher {
ngx_pool_t* pool_;
ngx_log_t* log_;
ngx_connection_t* command_connection_; // the command pipe
int pipe_fd_; // the write pipe end
ngx_resolver_t* resolver_;
int max_keepalive_requests_;
ngx_msec_t resolver_timeout_;
ngx_msec_t fetch_timeout_;
NgxEventConnection* event_connection_;
DISALLOW_COPY_AND_ASSIGN(NgxUrlAsyncFetcher);
};
-257
View File
@@ -1,257 +0,0 @@
// Copyright 2011 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: morlovich@google.com (Maksim Orlovich)
#include "pthread_shared_mem.h"
#include <fcntl.h>
#include <pthread.h>
#include <sys/mman.h>
#include <unistd.h>
#include <cerrno>
#include <cstddef>
#include <map>
#include <utility>
#include "net/instaweb/util/public/abstract_shared_mem.h"
#include "net/instaweb/util/public/abstract_mutex.h"
#include "net/instaweb/util/public/basictypes.h"
#include "net/instaweb/util/public/message_handler.h"
#include "net/instaweb/util/public/string.h"
namespace net_instaweb {
namespace ngx {
namespace {
// This implementation relies on readonly copies of old memory and shared R/W
// mappings being kept across a fork. It simply stashes addresses of
// shared mmap segments into a map where kid processes can pick them up.
// close() a fd logging failure and dealing with EINTR.
void CheckedClose(int fd, MessageHandler* message_handler) {
while (close(fd) != 0) {
if (errno != EINTR) {
message_handler->Message(kWarning, "Problem closing SHM segment fd:%d",
errno);
return;
}
}
}
// Unlike PthreadMutex this doesn't own the lock, but rather refers to an
// external one.
class PthreadSharedMemMutex : public AbstractMutex {
public:
explicit PthreadSharedMemMutex(pthread_mutex_t* external_mutex)
: external_mutex_(external_mutex) {}
virtual bool TryLock() {
return (pthread_mutex_trylock(external_mutex_) == 0);
}
virtual void Lock() {
pthread_mutex_lock(external_mutex_);
}
virtual void Unlock() {
pthread_mutex_unlock(external_mutex_);
}
private:
pthread_mutex_t* external_mutex_;
DISALLOW_COPY_AND_ASSIGN(PthreadSharedMemMutex);
};
class PthreadSharedMemSegment : public AbstractSharedMemSegment {
public:
// We will be representing memory mapped in the [base, base + size) range.
PthreadSharedMemSegment(char* base, size_t size, MessageHandler* handler)
: base_(base),
size_(size) {
}
virtual ~PthreadSharedMemSegment() {
}
virtual volatile char* Base() {
return base_;
}
virtual size_t SharedMutexSize() const {
return sizeof(pthread_mutex_t);
}
virtual bool InitializeSharedMutex(size_t offset, MessageHandler* handler) {
pthread_mutexattr_t attr;
if (pthread_mutexattr_init(&attr) != 0) {
handler->Message(kError, "pthread_mutexattr_init failed with errno:%d",
errno);
return false;
}
if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED) != 0) {
pthread_mutexattr_destroy(&attr);
handler->Message(
kError, "pthread_mutexattr_setpshared failed with errno:%d", errno);
return false;
}
if (pthread_mutex_init(MutexPtr(offset), &attr) != 0) {
pthread_mutexattr_destroy(&attr);
handler->Message(kError, "pthread_mutex_init failed with errno:%d",
errno);
return false;
}
pthread_mutexattr_destroy(&attr);
return true;
}
virtual AbstractMutex* AttachToSharedMutex(size_t offset) {
return new PthreadSharedMemMutex(MutexPtr(offset));
}
private:
pthread_mutex_t* MutexPtr(size_t offset) {
return reinterpret_cast<pthread_mutex_t*>(base_ + offset);
}
char* const base_;
const size_t size_;
DISALLOW_COPY_AND_ASSIGN(PthreadSharedMemSegment);
};
pthread_mutex_t segment_bases_lock = PTHREAD_MUTEX_INITIALIZER;
} // namespace
size_t PthreadSharedMem::s_instance_count_ = 0;
PthreadSharedMem::SegmentBaseMap* PthreadSharedMem::segment_bases_ = NULL;
PthreadSharedMem::PthreadSharedMem() {
instance_number_ = ++s_instance_count_;
}
PthreadSharedMem::~PthreadSharedMem() {
}
size_t PthreadSharedMem::SharedMutexSize() const {
return sizeof(pthread_mutex_t);
}
AbstractSharedMemSegment* PthreadSharedMem::CreateSegment(
const GoogleString& name, size_t size, MessageHandler* handler) {
GoogleString prefixed_name = PrefixSegmentName(name);
// Create the memory
int fd = open("/dev/zero", O_RDWR);
if (fd == -1) {
handler->Message(kError, "Unable to create SHM segment %s, errno=%d.",
prefixed_name.c_str(), errno);
return NULL;
}
// map it
char* base = reinterpret_cast<char*>(
mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
CheckedClose(fd, handler);
if (base == MAP_FAILED) {
return NULL;
}
SegmentBaseMap* bases = AcquireSegmentBases();
(*bases)[prefixed_name] = base;
UnlockSegmentBases();
return new PthreadSharedMemSegment(base, size, handler);
}
AbstractSharedMemSegment* PthreadSharedMem::AttachToSegment(
const GoogleString& name, size_t size, MessageHandler* handler) {
GoogleString prefixed_name = PrefixSegmentName(name);
SegmentBaseMap* bases = AcquireSegmentBases();
SegmentBaseMap::const_iterator i = bases->find(prefixed_name);
if (i == bases->end()) {
handler->Message(kError, "Unable to find SHM segment %s to attach to.",
prefixed_name.c_str());
UnlockSegmentBases();
return NULL;
}
char* base = i->second;
UnlockSegmentBases();
return new PthreadSharedMemSegment(base, size, handler);
}
void PthreadSharedMem::DestroySegment(const GoogleString& name,
MessageHandler* handler) {
GoogleString prefixed_name = PrefixSegmentName(name);
// Note that in the process state children will not see any mutations
// we make here, so it acts mostly for checking in that case.
SegmentBaseMap* bases = AcquireSegmentBases();
SegmentBaseMap::iterator i = bases->find(prefixed_name);
if (i != bases->end()) {
bases->erase(i);
if (bases->empty()) {
delete segment_bases_;
segment_bases_ = NULL;
}
} else {
handler->Message(kError, "Attempt to destroy unknown SHM segment %s.",
prefixed_name.c_str());
}
UnlockSegmentBases();
}
PthreadSharedMem::SegmentBaseMap* PthreadSharedMem::AcquireSegmentBases() {
PthreadSharedMemMutex lock(&segment_bases_lock);
lock.Lock();
if (segment_bases_ == NULL) {
segment_bases_ = new SegmentBaseMap();
}
return segment_bases_;
}
void PthreadSharedMem::UnlockSegmentBases() {
PthreadSharedMemMutex lock(&segment_bases_lock);
lock.Unlock();
}
GoogleString PthreadSharedMem::PrefixSegmentName(const GoogleString& name) {
GoogleString res;
StrAppend(&res, "[", IntegerToString(instance_number_), "]", name);
return res;
}
void PthreadSharedMem::Terminate() {
// Clean up the local memory associated with the maps to shared memory
// storage.
PthreadSharedMemMutex lock(&segment_bases_lock);
lock.Lock();
if (segment_bases_ != NULL) {
delete segment_bases_;
segment_bases_ = NULL;
}
lock.Unlock();
}
} // namespace ngx
} // namespace net_instaweb
-88
View File
@@ -1,88 +0,0 @@
// Copyright 2011 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: morlovich@google.com (Maksim Orlovich)
#ifndef NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_SHARED_MEM_H_
#define NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_SHARED_MEM_H_
#include <cstddef>
#include <map>
#include "net/instaweb/util/public/abstract_shared_mem.h"
#include "net/instaweb/util/public/basictypes.h"
#include "net/instaweb/util/public/string.h"
namespace net_instaweb {
class MessageHandler;
namespace ngx {
// POSIX shared memory support, using mmap/pthread_mutexattr_setpshared
// Supports both processes and threads, but processes that want to access it
// must be results of just fork (without exec), and all the CreateSegment
// calls must occur before the fork.
//
// This implementation is also not capable of deallocating segments except
// at exit, so it should not be used when the set of segments may be dynamic.
class PthreadSharedMem : public AbstractSharedMem {
public:
PthreadSharedMem();
virtual ~PthreadSharedMem();
virtual size_t SharedMutexSize() const;
virtual AbstractSharedMemSegment* CreateSegment(
const GoogleString& name, size_t size, MessageHandler* handler);
virtual AbstractSharedMemSegment* AttachToSegment(
const GoogleString& name, size_t size, MessageHandler* handler);
virtual void DestroySegment(const GoogleString& name,
MessageHandler* handler);
// Frees all lazy-initialized memory used to track shared-memory segments.
static void Terminate();
private:
typedef std::map<GoogleString, char*> SegmentBaseMap;
// Accessor for below. Note that the segment_bases_lock will be held at exit.
static SegmentBaseMap* AcquireSegmentBases();
static void UnlockSegmentBases();
// Prefixes the passed in segment name with the current instance number.
GoogleString PrefixSegmentName(const GoogleString& name);
// The root process stores segment locations here. Child processes will
// inherit a readonly copy of this map after the fork. Note that this is
// initialized in a thread-unsafe manner, given the above assumptions.
static SegmentBaseMap* segment_bases_;
// Holds the number of times a PthreadSharedMem has been created.
static size_t s_instance_count_;
// Used to prefix segment names, so that when two runtimes are active at the
// same moment they will not have overlapping segment names. This occurs in
// ngx_pagespeed during a configuration reload, where first a new factory is
// created, before destroying the old one.
size_t instance_number_;
DISALLOW_COPY_AND_ASSIGN(PthreadSharedMem);
};
} // namespace ngx
} // namespace net_instaweb
#endif // NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_SHARED_MEM_H_
Executable → Regular
+942 -975
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+50 -27
View File
@@ -1,21 +1,21 @@
#!/bin/bash
#
# Copyright 2013 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author: jefftk@google.com (Jeff Kaufman)
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Runs ngx_pagespeed system tests.
#
# Exits with status 0 if all tests pass.
@@ -23,10 +23,19 @@
# Exits with status 2 if command line args are wrong.
#
# Usage:
# ./run_tests.sh primary_port secondary_port mod_pagespeed_dir
# Example:
# ./run_tests.sh 8050 8051 /path/to/mod_pagespeed
# ./run_tests.sh
# Or:
# ./run_tests.sh /path/to/mod_pagespeed /path/to/nginx/binary
#
# If you built ngx_pagespeed with "scripts/build_ngx_pagespeed.sh --devel" then
# you don't need to pass any arguments to run_tests.sh. Otherwise, you'll need
# to tell it where to find a mod_pagespeed checkout (for example html files etc)
# and the nginx binary to test.
#
# By default the test script uses several ports. If you have a port conflict
# and need to override one you can do that by setting the relevant environment
# variable. For example:
# PRIMARY_PORT=1234 ./run_tests.sh /.../mod_pagespeed /.../nginx/binary
# Normally we test only with the native fetcher off. Set
# TEST_NATIVE_FETCHER=true to also test the native fetcher, set
@@ -43,26 +52,37 @@ RUN_TESTS=${RUN_TESTS:-true}
# true.
USE_VALGRIND=${USE_VALGRIND:-false}
if [ "$#" -ne 4 ] ; then
echo "Usage: $0 primary_port secondary_port mod_pagespeed_dir"
echo " nginx_executable"
if [ "$#" -eq 0 ]; then
MOD_PAGESPEED_DIR="testing-dependencies/mod_pagespeed/"
NGINX_EXECUTABLE="nginx/sbin/nginx"
elif [ "$#" -eq 2 ]; then
MOD_PAGESPEED_DIR="$1"
NGINX_EXECUTABLE="$2"
else
echo "Usage: $0 [mod_pagespeed_dir nginx_executable]"
exit 2
fi
PRIMARY_PORT="$1"
SECONDARY_PORT="$2"
MOD_PAGESPEED_DIR="$3"
NGINX_EXECUTABLE="$4"
: ${PRIMARY_PORT:=8050}
: ${SECONDARY_PORT:=8051}
: ${CONTROLLER_PORT:=8053}
: ${RCPORT:=9991}
: ${PAGESPEED_TEST_HOST:=selfsigned.modpagespeed.com}
: ${PHP_PORT:=9000}
this_dir="$( cd $(dirname "$0") && pwd)"
function run_test_checking_failure() {
"$MOD_PAGESPEED_DIR/install/start_php.sh" "$PHP_PORT"
USE_VALGRIND="$USE_VALGRIND" \
PRIMARY_PORT="$PRIMARY_PORT" \
SECONDARY_PORT="$SECONDARY_PORT" \
MOD_PAGESPEED_DIR="$MOD_PAGESPEED_DIR" \
NGINX_EXECUTABLE="$NGINX_EXECUTABLE" \
PAGESPEED_TEST_HOST="$PAGESPEED_TEST_HOST" \
RUN_TESTS="$RUN_TESTS" \
CONTROLLER_PORT="$CONTROLLER_PORT" \
RCPORT="$RCPORT" \
bash "$this_dir/nginx_system_test.sh"
STATUS=$?
echo "With $@ setup."
@@ -73,6 +93,9 @@ function run_test_checking_failure() {
3)
return # Only expected failures.
;;
4)
return # Return passing error code when running manually.
;;
*)
exit 1 # Real failure.
esac
+193
View File
@@ -0,0 +1,193 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License
# The first few suppressions can be found in other modules
# and easily found when searched for, and seem false positives.
{
<nginx false positive>
Memcheck:Param
socketcall.sendmsg(msg.msg_iov[i])
fun:__sendmsg_nocancel
fun:ngx_write_channel
fun:ngx_signal_worker_processes
fun:ngx_master_process_cycle
fun:main
}
{
<nginx false positive>
Memcheck:Param
socketcall.sendmsg(msg.msg_iov[i])
fun:__sendmsg_nocancel
fun:ngx_write_channel
fun:ngx_master_process_cycle
fun:main
}
{
<nginx false positive>
Memcheck:Param
socketcall.sendmsg(msg.msg_iov[i])
fun:__sendmsg_nocancel
fun:ngx_write_channel
fun:ngx_pass_open_channel
fun:ngx_start_cache_manager_processes
fun:ngx_master_process_cycle
fun:main
}
{
<nginx false positive>
Memcheck:Param
socketcall.sendmsg(msg.msg_iov[i])
fun:__sendmsg_nocancel
fun:ngx_write_channel
fun:ngx_pass_open_channel
fun:ngx_start_cache_manager_processes
fun:ngx_master_process_cycle
fun:main
}
{
<nginx false positive>
Memcheck:Leak
fun:malloc
fun:ngx_alloc
fun:ngx_event_process_init
fun:ngx_worker_process_init
fun:ngx_worker_process_cycle
fun:ngx_spawn_process
fun:ngx_start_worker_processes
fun:ngx_master_process_cycle
fun:main
}
{
<nginx false positive>
Memcheck:Param
socketcall.sendmsg(msg.msg_iov[i])
fun:__sendmsg_nocancel
fun:ngx_write_channel
fun:ngx_pass_open_channel
fun:ngx_start_worker_processes
fun:ngx_master_process_cycle
fun:main
}
# similar to http://trac.nginx.org/nginx/ticket/369
{
<nginx false positive>
Memcheck:Param
pwrite64(buf)
obj:/lib/x86_64-linux-gnu/libpthread-2.15.so
fun:ngx_write_file
fun:ngx_write_chain_to_file
fun:ngx_write_chain_to_temp_file
fun:ngx_event_pipe_write_chain_to_temp_file
fun:ngx_event_pipe
fun:ngx_http_upstream_process_upstream
fun:ngx_http_upstream_process_header
fun:ngx_http_upstream_handler
fun:ngx_epoll_process_events
fun:ngx_process_events_and_timers
fun:ngx_worker_process_cycle
}
# Mentioned in https://github.com/apache/incubator-pagespeed-ngx/issues/103
# Assuming a false postives as the issue is closed.
{
<nginx false positive>
Memcheck:Param
write(buf)
obj:/lib/x86_64-linux-gnu/libpthread-2.15.so
fun:ngx_log_error_core
fun:ngx_http_parse_complex_uri
fun:ngx_http_process_request_uri
fun:ngx_http_process_request_line
fun:ngx_http_wait_request_handler
fun:ngx_epoll_process_events
fun:ngx_process_events_and_timers
fun:ngx_worker_process_cycle
fun:ngx_spawn_process
fun:ngx_start_worker_processes
fun:ngx_master_process_cycle
}
# Extra suppresions for testing in release mode:
{
<re2 uninitialised value in optimized code>
Memcheck:Cond
fun:_ZN3re24Prog8OptimizeEv
...
}
{
<re2 uninitialised value in optimized code>
Memcheck:Value8
fun:_ZN3re24Prog8OptimizeEv
...
}
{
<re2 uninitialised value in optimized code>
Memcheck:Cond
fun:_ZN3re2L4AddQEPNS_9SparseSetEi
...
}
{
<re2 uninitialised value in optimized code>
Memcheck:Value8
fun:_ZN3re2L4AddQEPNS_9SparseSetEi
...
}
{
<re2 uninitialized value in optimized code>
Memcheck:Value8
fun:_ZN3re23DFA10AddToQueueEPNS0_5WorkqEij
...
}
{
<re2 uninitialized value in optimized code>
Memcheck:Cond
fun:_ZN3re23DFA10AddToQueueEPNS0_5WorkqEij
...
}
{
<re2 uninitialized value in optimized code>
Memcheck:Value8
fun:_ZNK3re210SparseSetTIvE8containsEi
...
}
{
<re2 uninitialized value in optimized code>
Memcheck:Cond
fun:_ZNK3re210SparseSetTIvE8containsEi
...
}
{
<re2 uninitialized value in optimized code>
Memcheck:Value8
fun:_ZNK3re211SparseArrayIiE9has_indexEi
...
}
{
<re2 uninitialized value in optimized code>
Memcheck:Cond
fun:_ZNK3re211SparseArrayIiE9has_indexEi
...
}