Skip to content

Commit

Permalink
Merge branch 'master' into fix-plan-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnny Wang authored Jul 30, 2024
2 parents 667c206 + 25e9ac8 commit 700b877
Show file tree
Hide file tree
Showing 137 changed files with 11,019 additions and 422 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Lint PR"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Configure which types are allowed.
# Default: /~https://github.com/commitizen/conventional-commit-types
types: |
bugfix # bug fixes
change # backward incompatible changes
doc # documentation changes including code comments
editor # code editor related configurations
feature # implementing a new feature
optimize # performance optimizations
refactor # code refactoring and other code rearrangement
style # coding style changes
tests # test suite changes
48 changes: 29 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
---
sudo: required
dist: trusty
dist: focal

branches:
only:
- "master"

os: linux

language: c

compiler:
- gcc
- clang

addons:
apt:
packages:
- cpanminus
- axel
- luarocks
- daemonize

cache:
directories:
Expand All @@ -29,10 +33,14 @@ env:
- LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1
- LUA_INCLUDE_DIR=$LUAJIT_INC
- LUA_CMODULE_DIR=/lib
- PCRE_VER=8.40
- PCRE_VER=8.45
- PCRE2_VER=10.37
- PCRE_PREFIX=/opt/pcre
- PCRE2_PREFIX=/opt/pcre2
- PCRE_LIB=$PCRE_PREFIX/lib
- PCRE2_LIB=$PCRE2_PREFIX/lib
- PCRE_INC=$PCRE_PREFIX/include
- PCRE2_INC=$PCRE2_PREFIX/include
- OPENSSL_PREFIX=/opt/ssl
- OPENSSL_LIB=$OPENSSL_PREFIX/lib
- OPENSSL_INC=$OPENSSL_PREFIX/include
Expand All @@ -41,24 +49,24 @@ env:
- TEST_NGINX_RANDOMIZE=1
- LUACHECK_VER=0.21.1
matrix:
- NGINX_VERSION=1.19.3 OPENSSL_VER=1.0.2u OPENSSL_PATCH_VER=1.0.2h
- NGINX_VERSION=1.19.3 OPENSSL_VER=1.1.0l OPENSSL_PATCH_VER=1.1.0d
- NGINX_VERSION=1.19.3 OPENSSL_VER=1.1.1g OPENSSL_PATCH_VER=1.1.1f
- NGINX_VERSION=1.25.3 OPENSSL_VER=1.1.1w OPENSSL_PATCH_VER=1.1.1f USE_PCRE2=Y
- NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.1w OPENSSL_PATCH_VER=1.1.1f

services:
- memcache

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

install:
- if [ ! -d download-cache ]; then mkdir download-cache; fi
- 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
- 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
- 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
- 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
- git clone /~https://github.com/openresty/openresty.git ../openresty
- git clone /~https://github.com/openresty/openresty-devel-utils.git
- git clone /~https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module
Expand All @@ -75,7 +83,7 @@ install:

script:
- cd luajit2/
- 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)
- 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)
- sudo make install PREFIX=$LUAJIT_PREFIX > build.log 2>&1 || (cat build.log && exit 1)
- cd ..
- cd lua-resty-lrucache && sudo make DESTDIR=$LUAJIT_PREFIX LUA_LIB_DIR=/share/lua/5.1 install && cd ..
Expand All @@ -86,18 +94,20 @@ script:
- make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1)
- sudo make PATH=$PATH install_sw > build.log 2>&1 || (cat build.log && exit 1)
- cd ../mockeagain/ && make CC=$CC -j$JOBS && cd ..
- 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 ..
- 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
- 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
- export PATH=$PWD/work/nginx/sbin:$PWD/openresty-devel-utils:$PATH
- export LD_PRELOAD=$PWD/mockeagain/mockeagain.so
- export LD_LIBRARY_PATH=$PWD/mockeagain:$LD_LIBRARY_PATH
- export TEST_NGINX_RESOLVER=8.8.4.4
- export NGX_BUILD_CC=$CC
- 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)
- export add_http3_module=--with-http_v3_module
- export disable_pcre2=--without-pcre2
- answer=`util/ver-ge "$NGINX_VERSION" 1.25.1`
- if [ "$OPENSSL_VER" = "1.1.0l" ] || [ "$answer" = "N" ]; then add_http3_module=""; fi
- if [ "$answer" = "N" ] || [ "$USE_PCRE2" = "Y" ]; then disable_pcre2=""; fi
- if [ "$USE_PCRE2" = "Y" ]; then PCRE_INC=$PCRE2_INC; PCRE_LIB=$PCRE2_LIB; fi
- 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)
- nginx -V
- ldd `which nginx`|grep -E 'luajit|ssl|pcre'
- prove -Itest-nginx/lib -j$JOBS -r t
- prove -I. -Itest-nginx/lib -j$JOBS -r t
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ LUA_INCLUDE_DIR ?= $(PREFIX)/include
LUA_LIB_DIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION)
INSTALL ?= install

SHELL := /bin/bash

.PHONY: all test install

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

test: all
PATH=$(OPENRESTY_PREFIX)/nginx/sbin:$$PATH prove -I../test-nginx/lib -r t
Expand Down
85 changes: 82 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Table of Contents
* [Synopsis](#synopsis)
* [Description](#description)
* [Prerequisites](#prerequisites)
* [Installation](#installation)
* [API Implemented](#api-implemented)
* [resty.core.hash](#restycorehash)
* [resty.core.base64](#restycorebase64)
Expand All @@ -20,16 +21,20 @@ Table of Contents
* [resty.core.shdict](#restycoreshdict)
* [resty.core.var](#restycorevar)
* [resty.core.ctx](#restycorectx)
* [get_ctx_table](#get_ctx_table)
* [resty.core.request](#restycorerequest)
* [resty.core.response](#restycoreresponse)
* [resty.core.misc](#restycoremisc)
* [resty.core.time](#restycoretime)
* [resty.core.worker](#restycoreworker)
* [resty.core.phase](#restycorephase)
* [resty.core.ndk](#restycorendk)
* [resty.core.socket](#restycoresocket)
* [resty.core.param](#restycoreparam)
* [ngx.semaphore](#ngxsemaphore)
* [ngx.balancer](#ngxbalancer)
* [ngx.ssl](#ngxssl)
* [ngx.ssl.clienthello](#ngxsslclienthello)
* [ngx.ssl.session](#ngxsslsession)
* [ngx.re](#ngxre)
* [ngx.resp](#ngxresp)
Expand All @@ -51,7 +56,7 @@ This library is production ready.
Synopsis
========

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

* 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 )
* [ngx_http_lua_module](/~https://github.com/openresty/lua-nginx-module) v0.10.18.
* [ngx_stream_lua_module](/~https://github.com/openresty/stream-lua-nginx-module) v0.0.9.
* [ngx_http_lua_module](/~https://github.com/openresty/lua-nginx-module) v0.10.25.
* [ngx_stream_lua_module](/~https://github.com/openresty/stream-lua-nginx-module) v0.0.13.
* [lua-resty-lrucache](/~https://github.com/openresty/lua-resty-lrucache)

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

Installation
============

By default, LuaJIT will search Lua files in /usr/local/share/lua/5.1/.
But `make install` will install this module to /usr/local/lib/lua.
So you may find the error like this:

```text
nginx: [alert] failed to load the 'resty.core' module
```

You can install this module with the following command to resolve the above problem.

```bash
cd lua-resty-core
sudo make install LUA_LIB_DIR=/usr/local/share/lua/5.1
```

You can also change the installation directory to any other directory you like with the LUA_LIB_DIR argument.

```bash
cd lua-resty-core
sudo make install LUA_LIB_DIR=/opt/nginx/lualib
```

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.

```
lua_package_path "/opt/nginx/lualib/?.lua;;";
```

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

API Implemented
===============

Expand Down Expand Up @@ -188,6 +226,21 @@ API Implemented

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

## get_ctx_table

**syntax:** *ctx = resty.core.ctx.get_ctx_table(ctx?)*

Similar to [ngx.ctx](#restycorectx) but it accepts an optional `ctx` argument.
It will use the `ctx` from caller instead of creating a new table
when the `ctx` table does not exist.

Notice: the `ctx` table will be used in the current request's whole life cycle.
Please be very careful when you try to reuse the `ctx` table.
You need to make sure there is no Lua code using or going to use the `ctx` table
in the current request before you reusing the `ctx` table in some other place.

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

## resty.core.request

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

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

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

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

Expand All @@ -248,6 +304,20 @@ API Implemented

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

## resty.core.socket

* [socket.setoption](/~https://github.com/openresty/lua-nginx-module#tcpsocksetoption)
* [socket.setclientcert](/~https://github.com/openresty/lua-nginx-module#tcpsocksetclientcert)
* [socket.sslhandshake](/~https://github.com/openresty/lua-nginx-module#tcpsocksslhandshake)

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

## resty.core.param

* [ngx.arg](/~https://github.com/openresty/lua-nginx-module#ngxarg) (getter only)

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

## ngx.semaphore

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

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

## ngx.ssl.clienthello

This Lua module provides a Lua API for post-processing SSL client hello message
for NGINX downstream SSL connections.

See the [documentation](./lib/ngx/ssl/clienthello.md) for this Lua module for more details.

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

## ngx.ssl.session

This Lua module provides a Lua API for manipulating SSL session data and IDs
Expand Down
Loading

0 comments on commit 700b877

Please sign in to comment.