Skip to content

Commit 3787343

Browse files
feat: support openresty 1.27.1.1 (#98)
1 parent 8ed17e7 commit 3787343

31 files changed

+10706
-51
lines changed

Diff for: patch/1.27.1.1/lua-resty-core-enable_keepalive.patch

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
diff --git lib/ngx/balancer.lua lib/ngx/balancer.lua
2+
index 18bdc2c..3a98f53 100644
3+
--- lib/ngx/balancer.lua
4+
+++ lib/ngx/balancer.lua
5+
@@ -3,7 +3,7 @@
6+
7+
local base = require "resty.core.base"
8+
base.allows_subsystem('http', 'stream')
9+
-
10+
+require "resty.core.hash"
11+
12+
local ffi = require "ffi"
13+
local C = ffi.C
14+
@@ -20,6 +20,7 @@ local error = error
15+
local type = type
16+
local tonumber = tonumber
17+
local max = math.max
18+
+local ngx_crc32_long = ngx.crc32_long
19+
20+
local subsystem = ngx.config.subsystem
21+
local ngx_lua_ffi_balancer_set_current_peer
22+
@@ -35,8 +36,7 @@ if subsystem == 'http' then
23+
ffi.cdef[[
24+
int ngx_http_lua_ffi_balancer_set_current_peer(ngx_http_request_t *r,
25+
const unsigned char *addr, size_t addr_len, int port,
26+
- const unsigned char *host, ssize_t host_len,
27+
- char **err);
28+
+ unsigned int cpool_crc32, unsigned int cpool_size, char **err);
29+
30+
int ngx_http_lua_ffi_balancer_enable_keepalive(ngx_http_request_t *r,
31+
unsigned long timeout, unsigned int max_requests, char **err);
32+
@@ -130,6 +130,7 @@ else
33+
error("unknown subsystem: " .. subsystem)
34+
end
35+
36+
+local DEFAULT_KEEPALIVE_POOL_SIZE = 30
37+
local DEFAULT_KEEPALIVE_IDLE_TIMEOUT = 60000
38+
local DEFAULT_KEEPALIVE_MAX_REQUESTS = 100
39+
40+
@@ -143,27 +144,61 @@ local peer_state_names = {
41+
local _M = { version = base.version }
42+
43+
if subsystem == "http" then
44+
- function _M.set_current_peer(addr, port, host)
45+
+ function _M.set_current_peer(addr, port, opts)
46+
local r = get_request()
47+
if not r then
48+
error("no request found")
49+
end
50+
51+
+ local pool_crc32
52+
+ local pool_size
53+
+ if opts then
54+
+ if type(opts) ~= "table" then
55+
+ error("bad argument #3 to 'set_current_peer' " ..
56+
+ "(table expected, got " .. type(opts) .. ")", 2)
57+
+ end
58+
+
59+
+ local pool = opts.pool
60+
+ pool_size = opts.pool_size
61+
+
62+
+ if pool then
63+
+ if type(pool) ~= "string" then
64+
+ error("bad option 'pool' to 'set_current_peer' " ..
65+
+ "(string expected, got " .. type(pool) .. ")", 2)
66+
+ end
67+
+
68+
+ pool_crc32 = ngx_crc32_long(pool)
69+
+ end
70+
+
71+
+ if pool_size then
72+
+ if type(pool_size) ~= "number" then
73+
+ error("bad option 'pool_size' to 'set_current_peer' " ..
74+
+ "(number expected, got " .. type(pool_size) .. ")", 2)
75+
+
76+
+ elseif pool_size < 1 then
77+
+ error("bad option 'pool_size' to 'set_current_peer' " ..
78+
+ "(expected > 0)", 2)
79+
+ end
80+
+ end
81+
+ end
82+
+
83+
if not port then
84+
port = 0
85+
+
86+
elseif type(port) ~= "number" then
87+
port = tonumber(port)
88+
end
89+
90+
- if host ~= nil and type(host) ~= "string" then
91+
- error("bad argument #3 to 'set_current_peer' "
92+
- .. "(string expected, got " .. type(host) .. ")")
93+
+ if not pool_crc32 then
94+
+ pool_crc32 = 0
95+
end
96+
97+
- local rc = ngx_lua_ffi_balancer_set_current_peer(r, addr, #addr,
98+
- port,
99+
- host,
100+
- host and #host or 0,
101+
+ if not pool_size then
102+
+ pool_size = DEFAULT_KEEPALIVE_POOL_SIZE
103+
+ end
104+
+
105+
+ local rc = ngx_lua_ffi_balancer_set_current_peer(r, addr, #addr, port,
106+
+ pool_crc32, pool_size,
107+
errmsg)
108+
if rc == FFI_OK then
109+
return true
110+
@@ -172,26 +207,26 @@ if subsystem == "http" then
111+
return nil, ffi_str(errmsg[0])
112+
end
113+
else
114+
- function _M.set_current_peer(addr, port, host)
115+
+ function _M.set_current_peer(addr, port, opts)
116+
local r = get_request()
117+
if not r then
118+
error("no request found")
119+
end
120+
121+
+ if opts then
122+
+ error("bad argument #3 to 'set_current_peer' ('opts' not yet " ..
123+
+ "implemented in " .. subsystem .. " subsystem)", 2)
124+
+ end
125+
+
126+
if not port then
127+
port = 0
128+
+
129+
elseif type(port) ~= "number" then
130+
port = tonumber(port)
131+
end
132+
133+
- if host ~= nil then
134+
- error("bad argument #3 to 'set_current_peer' ('host' not yet " ..
135+
- "implemented in " .. subsystem .. " subsystem)", 2)
136+
- end
137+
-
138+
local rc = ngx_lua_ffi_balancer_set_current_peer(r, addr, #addr,
139+
- port,
140+
- errmsg)
141+
+ port, errmsg)
142+
if rc == FFI_OK then
143+
return true
144+
end
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git lib/ngx/ssl.lua lib/ngx/ssl.lua
2+
index b696bea..f3b20e0 100644
3+
--- lib/ngx/ssl.lua
4+
+++ lib/ngx/ssl.lua
5+
@@ -100,7 +100,7 @@ if subsystem == 'http' then
6+
void ngx_http_lua_ffi_free_priv_key(void *cdata);
7+
8+
int ngx_http_lua_ffi_ssl_verify_client(void *r,
9+
- void *client_certs, void *trusted_certs, int depth, char **err);
10+
+ void *client_certs, void *trusted_certs, int depth, int reject_in_handshake, char **err);
11+
12+
int ngx_http_lua_ffi_ssl_client_random(ngx_http_request_t *r,
13+
const unsigned char *out, size_t *outlen, char **err);
14+
@@ -198,7 +198,7 @@ elseif subsystem == 'stream' then
15+
void ngx_stream_lua_ffi_free_priv_key(void *cdata);
16+
17+
int ngx_stream_lua_ffi_ssl_verify_client(void *r,
18+
- void *client_certs, void *trusted_certs, int depth, char **err);
19+
+ void *client_certs, void *trusted_certs, int depth, int reject_in_handshake, char **err);
20+
21+
int ngx_stream_lua_ffi_ssl_client_random(ngx_stream_lua_request_t *r,
22+
unsigned char *out, size_t *outlen, char **err);
23+
@@ -484,7 +484,7 @@ function _M.set_priv_key(priv_key)
24+
end
25+
26+
27+
-function _M.verify_client(client_certs, depth, trusted_certs)
28+
+function _M.verify_client(client_certs, depth, trusted_certs, reject_in_handshake)
29+
local r = get_request()
30+
if not r then
31+
error("no request found")
32+
@@ -494,8 +494,15 @@ function _M.verify_client(client_certs, depth, trusted_certs)
33+
depth = -1
34+
end
35+
36+
+ if reject_in_handshake == nil then
37+
+ -- reject by default so we can migrate to the new behavior
38+
+ -- without modifying Lua code
39+
+ reject_in_handshake = true
40+
+ end
41+
+
42+
+ local reject_in_handshake_int = reject_in_handshake and 1 or 0
43+
local rc = ngx_lua_ffi_ssl_verify_client(r, client_certs, trusted_certs,
44+
- depth, errmsg)
45+
+ depth, reject_in_handshake_int, errmsg)
46+
if rc == FFI_OK then
47+
return true
48+
end

0 commit comments

Comments
 (0)