Skip to content

Commit 700b877

Browse files
author
Johnny Wang
authored
Merge branch 'master' into fix-plan-tests
2 parents 667c206 + 25e9ac8 commit 700b877

File tree

137 files changed

+11019
-422
lines changed

Some content is hidden

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

137 files changed

+11019
-422
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: "Lint PR"
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
jobs:
11+
main:
12+
name: Validate PR title
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: amannn/action-semantic-pull-request@v4
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
with:
19+
# Configure which types are allowed.
20+
# Default: https://github.com/commitizen/conventional-commit-types
21+
types: |
22+
bugfix # bug fixes
23+
change # backward incompatible changes
24+
doc # documentation changes including code comments
25+
editor # code editor related configurations
26+
feature # implementing a new feature
27+
optimize # performance optimizations
28+
refactor # code refactoring and other code rearrangement
29+
style # coding style changes
30+
tests # test suite changes

.travis.yml

+29-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
---
12
sudo: required
2-
dist: trusty
3+
dist: focal
4+
5+
branches:
6+
only:
7+
- "master"
38

49
os: linux
510

611
language: c
712

813
compiler:
914
- gcc
10-
- clang
1115

1216
addons:
1317
apt:
1418
packages:
15-
- cpanminus
1619
- axel
1720
- luarocks
21+
- daemonize
1822

1923
cache:
2024
directories:
@@ -29,10 +33,14 @@ env:
2933
- LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1
3034
- LUA_INCLUDE_DIR=$LUAJIT_INC
3135
- LUA_CMODULE_DIR=/lib
32-
- PCRE_VER=8.40
36+
- PCRE_VER=8.45
37+
- PCRE2_VER=10.37
3338
- PCRE_PREFIX=/opt/pcre
39+
- PCRE2_PREFIX=/opt/pcre2
3440
- PCRE_LIB=$PCRE_PREFIX/lib
41+
- PCRE2_LIB=$PCRE2_PREFIX/lib
3542
- PCRE_INC=$PCRE_PREFIX/include
43+
- PCRE2_INC=$PCRE2_PREFIX/include
3644
- OPENSSL_PREFIX=/opt/ssl
3745
- OPENSSL_LIB=$OPENSSL_PREFIX/lib
3846
- OPENSSL_INC=$OPENSSL_PREFIX/include
@@ -41,24 +49,24 @@ env:
4149
- TEST_NGINX_RANDOMIZE=1
4250
- LUACHECK_VER=0.21.1
4351
matrix:
44-
- NGINX_VERSION=1.19.3 OPENSSL_VER=1.0.2u OPENSSL_PATCH_VER=1.0.2h
45-
- NGINX_VERSION=1.19.3 OPENSSL_VER=1.1.0l OPENSSL_PATCH_VER=1.1.0d
46-
- NGINX_VERSION=1.19.3 OPENSSL_VER=1.1.1g OPENSSL_PATCH_VER=1.1.1f
52+
- NGINX_VERSION=1.25.3 OPENSSL_VER=1.1.1w OPENSSL_PATCH_VER=1.1.1f USE_PCRE2=Y
53+
- NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.1w OPENSSL_PATCH_VER=1.1.1f
4754

4855
services:
4956
- memcache
5057

5158
before_install:
5259
- sudo luarocks install luacheck $LUACHECK_VER
53-
- luacheck -q .
60+
- luacheck --globals coroutine -q .
5461
- '! grep -n -P ''(?<=.{80}).+'' --color `find . -name ''*.lua''` || (echo "ERROR: Found Lua source lines exceeding 80 columns." > /dev/stderr; exit 1)'
5562
- '! grep -n -P ''\t+'' --color `find . -name ''*.lua''` || (echo "ERROR: Cannot use tabs." > /dev/stderr; exit 1)'
56-
- sudo cpanm --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
63+
- cpanm --sudo --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
5764

5865
install:
5966
- if [ ! -d download-cache ]; then mkdir download-cache; fi
6067
- if [ ! -f download-cache/openssl-$OPENSSL_VER.tar.gz ]; then wget -P download-cache https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz || wget -P download-cache https://www.openssl.org/source/old/${OPENSSL_VER//[a-z]/}/openssl-$OPENSSL_VER.tar.gz; fi
61-
- 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
68+
- if [ "$USE_PCRE2" != "Y" ] && [ ! -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
69+
- if [ "$USE_PCRE2" = "Y" ] && [ ! -f download-cache/pcre2-$PCRE2_VER.tar.gz ]; then wget -P download-cache https://downloads.sourceforge.net/project/pcre/pcre2/${PCRE2_VER}/pcre2-${PCRE2_VER}.tar.gz; fi
6270
- git clone https://github.com/openresty/openresty.git ../openresty
6371
- git clone https://github.com/openresty/openresty-devel-utils.git
6472
- git clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module
@@ -75,7 +83,7 @@ install:
7583

7684
script:
7785
- cd luajit2/
78-
- 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)
86+
- make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT -msse4.2 -O1 -DLUAJIT_SECURITY_STRID=0 -DLUAJIT_SECURITY_STRHASH=0 -DLUAJIT_SECURITY_PRNG=0 -DLUAJIT_SECURITY_MCODE=0 -DLUAJIT_TEST_FIXED_ORDER' > build.log 2>&1 || (cat build.log && exit 1)
7987
- sudo make install PREFIX=$LUAJIT_PREFIX > build.log 2>&1 || (cat build.log && exit 1)
8088
- cd ..
8189
- cd lua-resty-lrucache && sudo make DESTDIR=$LUAJIT_PREFIX LUA_LIB_DIR=/share/lua/5.1 install && cd ..
@@ -86,18 +94,20 @@ script:
8694
- make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1)
8795
- sudo make PATH=$PATH install_sw > build.log 2>&1 || (cat build.log && exit 1)
8896
- cd ../mockeagain/ && make CC=$CC -j$JOBS && cd ..
89-
- tar zxf download-cache/pcre-$PCRE_VER.tar.gz
90-
- cd pcre-$PCRE_VER/
91-
- ./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties > build.log 2>&1 || (cat build.log && exit 1)
92-
- make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1)
93-
- sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1)
94-
- cd ..
97+
- if [ "$USE_PCRE2" != "Y" ]; then tar zxf download-cache/pcre-$PCRE_VER.tar.gz; cd pcre-$PCRE_VER/; ./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi
98+
- if [ "$USE_PCRE2" = "Y" ]; then tar zxf download-cache/pcre2-$PCRE2_VER.tar.gz; cd pcre2-$PCRE2_VER/; ./configure --prefix=$PCRE2_PREFIX --enable-jit --enable-utf > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi
9599
- export PATH=$PWD/work/nginx/sbin:$PWD/openresty-devel-utils:$PATH
96100
- export LD_PRELOAD=$PWD/mockeagain/mockeagain.so
97101
- export LD_LIBRARY_PATH=$PWD/mockeagain:$LD_LIBRARY_PATH
98102
- export TEST_NGINX_RESOLVER=8.8.4.4
99103
- export NGX_BUILD_CC=$CC
100-
- ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-pcre-jit --with-cc-opt="-I$OPENSSL_INC -I$PCRE_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB -L$PCRE_LIB -Wl,-rpath,$PCRE_LIB" --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../set-misc-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --with-debug --with-stream_ssl_module --with-stream --with-ipv6 --add-module=../stream-lua-nginx-module > build.log 2>&1 || (cat build.log && exit 1)
104+
- export add_http3_module=--with-http_v3_module
105+
- export disable_pcre2=--without-pcre2
106+
- answer=`util/ver-ge "$NGINX_VERSION" 1.25.1`
107+
- if [ "$OPENSSL_VER" = "1.1.0l" ] || [ "$answer" = "N" ]; then add_http3_module=""; fi
108+
- if [ "$answer" = "N" ] || [ "$USE_PCRE2" = "Y" ]; then disable_pcre2=""; fi
109+
- if [ "$USE_PCRE2" = "Y" ]; then PCRE_INC=$PCRE2_INC; PCRE_LIB=$PCRE2_LIB; fi
110+
- ngx-build $NGINX_VERSION $disable_pcre2 $add_http3_module --with-http_v2_module --with-http_realip_module --with-http_ssl_module --with-pcre-jit --with-cc-opt="-I$OPENSSL_INC -I$PCRE_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB -L$PCRE_LIB -Wl,-rpath,$PCRE_LIB" --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../set-misc-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --with-debug --with-stream_ssl_module --with-stream --with-ipv6 --add-module=../stream-lua-nginx-module > build.log 2>&1 || (cat build.log && exit 1)
101111
- nginx -V
102112
- ldd `which nginx`|grep -E 'luajit|ssl|pcre'
103-
- prove -Itest-nginx/lib -j$JOBS -r t
113+
- prove -I. -Itest-nginx/lib -j$JOBS -r t

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ LUA_INCLUDE_DIR ?= $(PREFIX)/include
66
LUA_LIB_DIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION)
77
INSTALL ?= install
88

9+
SHELL := /bin/bash
10+
911
.PHONY: all test install
1012

1113
all: ;
@@ -18,6 +20,13 @@ install: all
1820
$(INSTALL) lib/resty/core/*.lua $(DESTDIR)$(LUA_LIB_DIR)/resty/core/
1921
$(INSTALL) lib/ngx/*.lua $(DESTDIR)$(LUA_LIB_DIR)/ngx/
2022
$(INSTALL) lib/ngx/ssl/*.lua $(DESTDIR)$(LUA_LIB_DIR)/ngx/ssl/
23+
ifeq ($(LUA_LIB_DIR),/usr/local/lib/lua/)
24+
@echo
25+
@echo -e "\033[33mPLEASE NOTE: \033[0m"
26+
@echo -e "\033[33mThe necessary lua_package_path directive needs to be added to nginx.conf\033[0m"
27+
@echo -e "\033[33min the http context, because \"/usr/local/lib/lua/\" is not in LuaJIT’s default search path.\033[0m"
28+
@echo -e "\033[33mRefer to the Installation section of README.markdown.\033[0m"
29+
endif
2130

2231
test: all
2332
PATH=$(OPENRESTY_PREFIX)/nginx/sbin:$$PATH prove -I../test-nginx/lib -r t

README.markdown

+82-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Table of Contents
1111
* [Synopsis](#synopsis)
1212
* [Description](#description)
1313
* [Prerequisites](#prerequisites)
14+
* [Installation](#installation)
1415
* [API Implemented](#api-implemented)
1516
* [resty.core.hash](#restycorehash)
1617
* [resty.core.base64](#restycorebase64)
@@ -20,16 +21,20 @@ Table of Contents
2021
* [resty.core.shdict](#restycoreshdict)
2122
* [resty.core.var](#restycorevar)
2223
* [resty.core.ctx](#restycorectx)
24+
* [get_ctx_table](#get_ctx_table)
2325
* [resty.core.request](#restycorerequest)
2426
* [resty.core.response](#restycoreresponse)
2527
* [resty.core.misc](#restycoremisc)
2628
* [resty.core.time](#restycoretime)
2729
* [resty.core.worker](#restycoreworker)
2830
* [resty.core.phase](#restycorephase)
2931
* [resty.core.ndk](#restycorendk)
32+
* [resty.core.socket](#restycoresocket)
33+
* [resty.core.param](#restycoreparam)
3034
* [ngx.semaphore](#ngxsemaphore)
3135
* [ngx.balancer](#ngxbalancer)
3236
* [ngx.ssl](#ngxssl)
37+
* [ngx.ssl.clienthello](#ngxsslclienthello)
3338
* [ngx.ssl.session](#ngxsslsession)
3439
* [ngx.re](#ngxre)
3540
* [ngx.resp](#ngxresp)
@@ -51,7 +56,7 @@ This library is production ready.
5156
Synopsis
5257
========
5358

54-
This library is automatically loaded by default in OpenResty 1.15.8.1. This
59+
This library is automatically loaded by default since OpenResty 1.15.8.1. This
5560
behavior can be disabled via the
5661
[lua_load_resty_core](https://github.com/openresty/lua-nginx-module#lua_load_resty_core)
5762
directive, but note that the use of this library is vividly recommended, as its
@@ -108,12 +113,45 @@ of this library in the particular OpenResty release you are using. Otherwise you
108113
into serious compatibility issues.
109114

110115
* 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 )
111-
* [ngx_http_lua_module](https://github.com/openresty/lua-nginx-module) v0.10.18.
112-
* [ngx_stream_lua_module](https://github.com/openresty/stream-lua-nginx-module) v0.0.9.
116+
* [ngx_http_lua_module](https://github.com/openresty/lua-nginx-module) v0.10.25.
117+
* [ngx_stream_lua_module](https://github.com/openresty/stream-lua-nginx-module) v0.0.13.
113118
* [lua-resty-lrucache](https://github.com/openresty/lua-resty-lrucache)
114119

115120
[Back to TOC](#table-of-contents)
116121

122+
Installation
123+
============
124+
125+
By default, LuaJIT will search Lua files in /usr/local/share/lua/5.1/.
126+
But `make install` will install this module to /usr/local/lib/lua.
127+
So you may find the error like this:
128+
129+
```text
130+
nginx: [alert] failed to load the 'resty.core' module
131+
```
132+
133+
You can install this module with the following command to resolve the above problem.
134+
135+
```bash
136+
cd lua-resty-core
137+
sudo make install LUA_LIB_DIR=/usr/local/share/lua/5.1
138+
```
139+
140+
You can also change the installation directory to any other directory you like with the LUA_LIB_DIR argument.
141+
142+
```bash
143+
cd lua-resty-core
144+
sudo make install LUA_LIB_DIR=/opt/nginx/lualib
145+
```
146+
147+
After that, you need to add the above directory to the LuaJIT search direcotries with `lua_package_path` nginx directive in the http context and stream context.
148+
149+
```
150+
lua_package_path "/opt/nginx/lualib/?.lua;;";
151+
```
152+
153+
[Back to TOC](#table-of-contents)
154+
117155
API Implemented
118156
===============
119157

@@ -188,6 +226,21 @@ API Implemented
188226

189227
[Back to TOC](#table-of-contents)
190228

229+
## get_ctx_table
230+
231+
**syntax:** *ctx = resty.core.ctx.get_ctx_table(ctx?)*
232+
233+
Similar to [ngx.ctx](#restycorectx) but it accepts an optional `ctx` argument.
234+
It will use the `ctx` from caller instead of creating a new table
235+
when the `ctx` table does not exist.
236+
237+
Notice: the `ctx` table will be used in the current request's whole life cycle.
238+
Please be very careful when you try to reuse the `ctx` table.
239+
You need to make sure there is no Lua code using or going to use the `ctx` table
240+
in the current request before you reusing the `ctx` table in some other place.
241+
242+
[Back to TOC](#table-of-contents)
243+
191244
## resty.core.request
192245

193246
* [ngx.req.get_headers](https://github.com/openresty/lua-nginx-module#ngxreqget_headers)
@@ -211,6 +264,7 @@ API Implemented
211264
* [ngx.status](https://github.com/openresty/lua-nginx-module#ngxstatus)
212265
* [ngx.is_subrequest](https://github.com/openresty/lua-nginx-module#ngxis_subrequest)
213266
* [ngx.headers_sent](https://github.com/openresty/lua-nginx-module#ngxheaders_sent)
267+
* [ngx.req.is_internal](https://github.com/openresty/lua-nginx-module#ngxreqis_internal)
214268

215269
[Back to TOC](#table-of-contents)
216270

@@ -224,6 +278,8 @@ API Implemented
224278
* [ngx.cookie_time](https://github.com/openresty/lua-nginx-module#ngxcookie_time)
225279
* [ngx.http_time](https://github.com/openresty/lua-nginx-module#ngxhttp_time)
226280
* [ngx.parse_http_time](https://github.com/openresty/lua-nginx-module#ngxparse_http_time)
281+
* [monotonic_msec](./lib/resty/core/time.md#monotonic_msec)
282+
* [monotonic_time](./lib/resty/core/time.md#monotonic_time)
227283

228284
[Back to TOC](#table-of-contents)
229285

@@ -248,6 +304,20 @@ API Implemented
248304

249305
[Back to TOC](#table-of-contents)
250306

307+
## resty.core.socket
308+
309+
* [socket.setoption](https://github.com/openresty/lua-nginx-module#tcpsocksetoption)
310+
* [socket.setclientcert](https://github.com/openresty/lua-nginx-module#tcpsocksetclientcert)
311+
* [socket.sslhandshake](https://github.com/openresty/lua-nginx-module#tcpsocksslhandshake)
312+
313+
[Back to TOC](#table-of-contents)
314+
315+
## resty.core.param
316+
317+
* [ngx.arg](https://github.com/openresty/lua-nginx-module#ngxarg) (getter only)
318+
319+
[Back to TOC](#table-of-contents)
320+
251321
## ngx.semaphore
252322

253323
This Lua module implements a semaphore API for efficient "light thread" synchronization,
@@ -274,6 +344,15 @@ See the [documentation](./lib/ngx/ssl.md) for this Lua module for more details.
274344

275345
[Back to TOC](#table-of-contents)
276346

347+
## ngx.ssl.clienthello
348+
349+
This Lua module provides a Lua API for post-processing SSL client hello message
350+
for NGINX downstream SSL connections.
351+
352+
See the [documentation](./lib/ngx/ssl/clienthello.md) for this Lua module for more details.
353+
354+
[Back to TOC](#table-of-contents)
355+
277356
## ngx.ssl.session
278357

279358
This Lua module provides a Lua API for manipulating SSL session data and IDs

0 commit comments

Comments
 (0)