Skip to content

Commit e7eeecd

Browse files
authored
Merge pull request #1 from openresty/master
upgrade nginx
2 parents 3fc7c3c + 47c22c0 commit e7eeecd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+5011
-619
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
This place is for bug reports and development discussions only. For general questions and
2+
discussions, please join the openresty-en mailing list instead: https://groups.google.com/group/openresty-en.
3+
If you want to use Chinese, please join the openresty (Chinese) mailing list instead: https://groups.google.com/group/openresty.
4+
Do not use Chinese in this place.
5+
6+
Before you open a new issue, please search the internet and make sure it is not duplicate.
7+
8+
Ensure you have provided the following details while reporting a problem:
9+
10+
- [ ] The exact version of the related software, including but not limited to the OpenResty version
11+
(if any), the NGINX core version, the `ngx_lua` module version(via `openresty -V` or `nginx -V`),
12+
and the `lua-resty-core` version(via `resty -e 'print(require("resty.core").version)'`),
13+
and your operating system version(via `uname -a`).
14+
- [ ] **A minimal and standalone test case** that others can easily run on their side and
15+
reproduce the issue you are seeing.
16+
- [ ] Do not simply say "something is broken" or "something does not work". Always provide
17+
as much details as possible. Always describe **the symptoms and your expected results**.
18+
19+
You can (temporarily) enable the nginx debugging logs to see the internal workings
20+
of NGINX in your nginx''s `error.log` file. See http://nginx.org/en/docs/debugging_log.html
21+
The same instructions apply equally well to OpenResty.
22+
23+
If you are seeing crashes, please provide the full backtrace for the crash. See
24+
https://www.nginx.com/resources/wiki/start/topics/tutorials/debugging/#core-dump
25+
for more details.
26+
27+
Thanks for your cooperation.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
I hereby granted the copyright of the changes in this pull request
2+
to the authors of this lua-resty-core project.

.luacheckrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
std = 'ngx_lua'
2+
unused_args = false
3+
read_globals = {
4+
"coroutine._yield"
5+
}

.travis.yml

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,52 @@ compiler:
99
- gcc
1010
- clang
1111

12+
addons:
13+
apt:
14+
packages:
15+
- cpanminus
16+
- axel
17+
- luarocks
18+
1219
cache:
1320
directories:
1421
- download-cache
1522

1623
env:
1724
global:
18-
- JOBS=3
25+
- JOBS=2
1926
- NGX_BUILD_JOBS=$JOBS
2027
- LUAJIT_PREFIX=/opt/luajit21
2128
- LUAJIT_LIB=$LUAJIT_PREFIX/lib
2229
- LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1
2330
- LUA_INCLUDE_DIR=$LUAJIT_INC
2431
- LUA_CMODULE_DIR=/lib
32+
- PCRE_VER=8.40
2533
- OPENSSL_PREFIX=/opt/ssl
2634
- OPENSSL_LIB=$OPENSSL_PREFIX/lib
2735
- OPENSSL_INC=$OPENSSL_PREFIX/include
28-
- OPENSSL_VER=1.0.2h
36+
- OPENSSL_VER=1.0.2j
2937
- LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH
30-
- TEST_NGINX_SLEEP=0.006
38+
- TEST_NGINX_SLEEP=0.005
39+
- TEST_NGINX_RANDOMIZE=1
3140
matrix:
3241
- NGINX_VERSION=1.9.15
33-
# - NGINX_VERSION=1.10.0
42+
- NGINX_VERSION=1.11.2
43+
44+
before_install:
45+
- sudo luarocks install luacheck
46+
- luacheck -q .
47+
- '! grep -n -P ''(?<=.{80}).+'' --color `find . -name ''*.lua''` || (echo "ERROR: Found Lua source lines exceeding 80 columns." > /dev/stderr; exit 1)'
48+
- '! grep -n -P ''\t+'' --color `find . -name ''*.lua''` || (echo "ERROR: Cannot use tabs." > /dev/stderr; exit 1)'
49+
- sudo cpanm --notest Test::Nginx > build.log 2>&1 || (cat build.log && exit 1)
3450

3551
install:
3652
- if [ ! -d download-cache ]; then mkdir download-cache; fi
3753
- if [ ! -f download-cache/openssl-$OPENSSL_VER.tar.gz ]; then wget -O download-cache/openssl-$OPENSSL_VER.tar.gz https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz; fi
38-
- sudo apt-get install -qq -y cpanminus axel
39-
- sudo cpanm --notest Test::Nginx > build.log 2>&1 || (cat build.log && exit 1)
54+
- if [ ! -f download-cache/pcre-$PCRE_VER.tar.gz ]; then wget -P download-cache http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-$PCRE_VER.tar.gz; fi
4055
- wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
4156
- git clone https://github.com/openresty/openresty.git ../openresty
42-
- git clone https://github.com/openresty/nginx-devel-utils.git
57+
- git clone https://github.com/openresty/openresty-devel-utils.git
4358
- git clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module
4459
- git clone https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module
4560
- git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx
@@ -48,27 +63,29 @@ install:
4863
- git clone https://github.com/openresty/headers-more-nginx-module.git ../headers-more-nginx-module
4964
- git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git
5065
- git clone https://github.com/openresty/mockeagain.git
66+
- git clone https://github.com/openresty/test-nginx.git
5167

5268
script:
5369
- cd luajit2/
54-
- make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT' > build.log 2>&1 || (cat build.log && exit 1)
70+
- make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT -msse4.2' > build.log 2>&1 || (cat build.log && exit 1)
5571
- sudo make install PREFIX=$LUAJIT_PREFIX > build.log 2>&1 || (cat build.log && exit 1)
5672
- cd ..
5773
- cd lua-resty-lrucache && sudo make DESTDIR=$LUAJIT_PREFIX LUA_LIB_DIR=/share/lua/5.1 install && cd ..
5874
- tar zxf download-cache/openssl-$OPENSSL_VER.tar.gz
5975
- cd openssl-$OPENSSL_VER/
60-
- wget https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-$OPENSSL_VER-sess_set_get_cb_yield.patch
61-
- patch -p1 < openssl-$OPENSSL_VER-sess_set_get_cb_yield.patch
76+
- if [ ! -f openssl-1.0.2h-sess_set_get_cb_yield.patch ]; then wget -O openssl-1.0.2h-sess_set_get_cb_yield.patch https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-1.0.2h-sess_set_get_cb_yield.patch; fi
77+
- patch -p1 < openssl-1.0.2h-sess_set_get_cb_yield.patch
6278
- ./config shared --prefix=$OPENSSL_PREFIX -DPURIFY > build.log 2>&1 || (cat build.log && exit 1)
6379
- make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1)
6480
- sudo make PATH=$PATH install_sw > build.log 2>&1 || (cat build.log && exit 1)
6581
- cd ../mockeagain/ && make CC=$CC -j$JOBS && cd ..
66-
- export PATH=$PWD/work/nginx/sbin:$PWD/nginx-devel-utils:$PATH
82+
- tar zxf download-cache/pcre-$PCRE_VER.tar.gz
83+
- export PATH=$PWD/work/nginx/sbin:$PWD/openresty-devel-utils:$PATH
6784
- export LD_PRELOAD=$PWD/mockeagain/mockeagain.so
6885
- export LD_LIBRARY_PATH=$PWD/mockeagain:$LD_LIBRARY_PATH
6986
- export TEST_NGINX_RESOLVER=8.8.4.4
7087
- export NGX_BUILD_CC=$CC
71-
- ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-cc-opt="-I$OPENSSL_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB" --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --with-debug > build.log 2>&1 || (cat build.log && exit 1)
88+
- ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-pcre=../../pcre-$PCRE_VER --with-pcre-jit --with-cc-opt="-I$OPENSSL_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB" --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --with-debug > build.log 2>&1 || (cat build.log && exit 1)
7289
- nginx -V
7390
- ldd `which nginx`|grep -E 'luajit|ssl|pcre'
74-
- prove -r t
91+
- prove -Itest-nginx/lib -j$JOBS -r t

README.markdown

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Table of Contents
2929
* [ngx.balancer](#ngxbalancer)
3030
* [ngx.ssl](#ngxssl)
3131
* [ngx.ssl.session](#ngxsslsession)
32+
* [ngx.re](#ngxre)
33+
* [ngx.process](#ngxprocess)
34+
* [ngx.errlog](#ngxerrlog)
3235
* [Caveat](#caveat)
3336
* [TODO](#todo)
3437
* [Author](#author)
@@ -83,8 +86,12 @@ and requirements.
8386
Prerequisites
8487
=============
8588

89+
**WARNING** This library is included with every OpenResty release. You should use the bundled version
90+
of this library in the particular OpenResty release you are using. Otherwise you may run
91+
into serious comaptibility issues.
92+
8693
* LuaJIT 2.1 (for now, it is the v2.1 git branch in the official luajit-2.0 git repository: http://luajit.org/download.html )
87-
* [ngx_lua](https://github.com/openresty/lua-nginx-module) v0.10.6 or later.
94+
* [ngx_lua](https://github.com/openresty/lua-nginx-module) v0.10.9 or later.
8895
* [lua-resty-lrucache](https://github.com/openresty/lua-resty-lrucache)
8996

9097
[Back to TOC](#table-of-contents)
@@ -235,6 +242,35 @@ See the [documentation](./lib/ngx/ssl/session.md) for this Lua module for more d
235242

236243
[Back to TOC](#table-of-contents)
237244

245+
## ngx.re
246+
247+
This Lua module provides a Lua API which implements convenience utilities for
248+
the `ngx.re` API.
249+
250+
See the [documentation](./lib/ngx/re.md) for this Lua module for more details.
251+
252+
[Back to TOC](#table-of-contents)
253+
254+
## ngx.process
255+
256+
This Lua module is used to manage the nginx process in Lua.
257+
258+
See the [documentation](./lib/ngx/process.md) for this Lua module for more details.
259+
260+
This module was first introduced in lua-resty-core v0.1.12.
261+
262+
[Back to TOC](#table-of-contents)
263+
264+
## ngx.errlog
265+
266+
This Lua module provides Lua API to capture and manage nginx error log messages.
267+
268+
See the [documentation](./lib/ngx/errlog.md) for this Lua module for more details.
269+
270+
This module was first introduced in lua-resty-core v0.1.12.
271+
272+
[Back to TOC](#table-of-contents)
273+
238274
Caveat
239275
======
240276

@@ -256,7 +292,7 @@ TODO
256292
Author
257293
======
258294

259-
Yichun "agentzh" Zhang (章亦春) <[email protected]>, CloudFlare Inc.
295+
Yichun "agentzh" Zhang (章亦春) <[email protected]>, OpenResty Inc.
260296

261297
[Back to TOC](#table-of-contents)
262298

@@ -265,7 +301,7 @@ Copyright and License
265301

266302
This module is licensed under the BSD license.
267303

268-
Copyright (C) 2013-2016, by Yichun "agentzh" Zhang, CloudFlare Inc.
304+
Copyright (C) 2013-2017, by Yichun "agentzh" Zhang, OpenResty Inc.
269305

270306
All rights reserved.
271307

dist.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=lua-resty-core
2+
abstract=New FFI-based Lua API for the ngx_lua module
3+
author=Yichun "agentzh" Zhang (agentzh)
4+
is_original=yes
5+
license=2bsd
6+
lib_dir=lib
7+
doc_dir=lib
8+
repo_link=https://github.com/openresty/lua-resty-core
9+
main_module=lib/resty/core/base.lua
10+
requires = luajit >= 2.1.0, nginx >= 1.11.2, ngx_http_lua = 0.10.9, openresty/lua-resty-lrucache >= 0.06

lib/ngx/balancer.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ Description
8080
===========
8181

8282
This Lua module provides API functions to allow defining highly dynamic NGINX load balancers for
83-
any existing nginx upstream modules like [http://nginx.org/en/docs/http/ngx_http_proxy_module.html ngx_proxy] and
84-
[http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html ngx_fastcgi].
83+
any existing nginx upstream modules like [ngx_proxy](http://nginx.org/en/docs/http/ngx_http_proxy_module.html) and
84+
[ngx_fastcgi](http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html).
8585

8686
It allows you to dynamically select a backend peer to connect to (or retry) on a per-request
8787
basis from a list of backend peers which may also be dynamic.
@@ -173,7 +173,7 @@ Zero and negative timeout values are not allowed.
173173

174174
You can specify millisecond precision in the timeout values by using floating point numbers like 0.001 (which means 1ms).
175175

176-
Returns `true` when the operation is successul; returns `nil` and a string describing the error
176+
Returns `true` when the operation is successful; returns `nil` and a string describing the error
177177
otherwise.
178178

179179
This only affects the current downstream request. It is not a global change.
@@ -216,7 +216,7 @@ Please report bugs or submit patches by
216216
Author
217217
======
218218

219-
Yichun Zhang &lt;[email protected]&gt; (agentzh), CloudFlare Inc.
219+
Yichun Zhang &lt;[email protected]&gt; (agentzh), OpenResty Inc.
220220

221221
[Back to TOC](#table-of-contents)
222222

@@ -225,7 +225,7 @@ Copyright and License
225225

226226
This module is licensed under the BSD license.
227227

228-
Copyright (C) 2015, by Yichun "agentzh" Zhang, CloudFlare Inc.
228+
Copyright (C) 2015-2017, by Yichun "agentzh" Zhang, OpenResty Inc.
229229

230230
All rights reserved.
231231

lib/ngx/errlog.lua

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
-- Copyright (C) Yichun Zhang (agentzh)
2+
3+
4+
local ffi = require 'ffi'
5+
local base = require "resty.core.base"
6+
local ffi_string = ffi.string
7+
local get_string_buf = base.get_string_buf
8+
local get_size_ptr = base.get_size_ptr
9+
local C = ffi.C
10+
local new_tab = base.new_tab
11+
local ffi_new = ffi.new
12+
local charpp = ffi_new("char *[1]")
13+
local intp = ffi.new("int[1]")
14+
local num_value = ffi_new("double[1]")
15+
local getfenv = getfenv
16+
local tonumber = tonumber
17+
18+
19+
local _M = { version = base.version }
20+
21+
22+
ffi.cdef[[
23+
int ngx_http_lua_ffi_errlog_set_filter_level(int level, unsigned char *err,
24+
size_t *errlen);
25+
int ngx_http_lua_ffi_errlog_get_msg(char **log, int *loglevel,
26+
unsigned char *err, size_t *errlen, double *log_time);
27+
28+
int ngx_http_lua_ffi_errlog_get_sys_filter_level(ngx_http_request_t *r);
29+
]]
30+
31+
32+
local ERR_BUF_SIZE = 128
33+
local FFI_ERROR = base.FFI_ERROR
34+
35+
36+
function _M.set_filter_level(level)
37+
if not level then
38+
return nil, [[missing "level" argument]]
39+
end
40+
41+
local err = get_string_buf(ERR_BUF_SIZE)
42+
local errlen = get_size_ptr()
43+
errlen[0] = ERR_BUF_SIZE
44+
local rc = C.ngx_http_lua_ffi_errlog_set_filter_level(level, err, errlen)
45+
46+
if rc == FFI_ERROR then
47+
return nil, ffi_string(err, errlen[0])
48+
end
49+
50+
return true
51+
end
52+
53+
54+
function _M.get_logs(max, logs)
55+
local err = get_string_buf(ERR_BUF_SIZE)
56+
local errlen = get_size_ptr()
57+
errlen[0] = ERR_BUF_SIZE
58+
59+
local log = charpp
60+
local loglevel = intp
61+
local log_time = num_value
62+
63+
max = max or 10
64+
65+
if not logs then
66+
logs = new_tab(max * 3 + 1, 0)
67+
end
68+
69+
local count = 0
70+
71+
for i = 1, max do
72+
local loglen = C.ngx_http_lua_ffi_errlog_get_msg(log, loglevel, err,
73+
errlen, log_time)
74+
if loglen == FFI_ERROR then
75+
return nil, ffi_string(err, errlen[0])
76+
end
77+
78+
if loglen > 0 then
79+
logs[count + 1] = loglevel[0]
80+
logs[count + 2] = log_time[0]
81+
logs[count + 3] = ffi_string(log[0], loglen)
82+
83+
count = count + 3
84+
end
85+
86+
if loglen < 0 then -- no error log
87+
logs[count + 1] = nil
88+
break
89+
end
90+
91+
if i == max then -- last one
92+
logs[count + 1] = nil
93+
break
94+
end
95+
end
96+
97+
return logs
98+
end
99+
100+
101+
function _M.get_sys_filter_level()
102+
local r = getfenv(0).__ngx_req
103+
return tonumber(C.ngx_http_lua_ffi_errlog_get_sys_filter_level(r))
104+
end
105+
106+
107+
return _M

0 commit comments

Comments
 (0)