Skip to content

Commit e221773

Browse files
committed
feature: tcpsock sslhandshake alpn
1 parent 5eb0d37 commit e221773

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/resty/core/socket.lua

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ if subsystem == 'http' then
185185
local errmsg = base.get_errmsg_ptr()
186186
local session_ptr = ffi_new("void *[1]")
187187
local server_name_str = ffi_new("ngx_str_t[1]")
188+
local alpn_str = ffi_new("ngx_str_t[1]")
188189
local openssl_error_code = ffi_new("int[1]")
189190

190191

@@ -217,7 +218,7 @@ end
217218

218219

219220
local function sslhandshake(cosocket, reused_session, server_name, ssl_verify,
220-
send_status_req, ...)
221+
send_status_req, alpn, ...)
221222

222223
local n = select("#", ...)
223224
if not cosocket or n > 0 then
@@ -241,6 +242,21 @@ local function sslhandshake(cosocket, reused_session, server_name, ssl_verify,
241242
server_name_str[0].len = 0
242243
end
243244

245+
if alpn then
246+
local alpn = {}
247+
for _, proto_str in ipairs(alpn) do
248+
alpn[#alpn + 1] = string.len(proto_str)
249+
for _, proto_byte in ipairs({ string.byte(proto_str, 1, #proto_str) }) do
250+
alpn[#alpn + 1] = proto_byte
251+
end
252+
end
253+
alpn_str[0].data = ffi.new("unsigned char[?]", #alpn, alpn)
254+
alpn_str[0].len = #alpn
255+
else
256+
alpn_str[0].data = nil
257+
alpn_str[0].len = 0
258+
end
259+
244260
local u = get_tcp_socket(cosocket)
245261

246262
local rc = C.ngx_http_lua_ffi_socket_tcp_sslhandshake(r, u,
@@ -251,6 +267,7 @@ local function sslhandshake(cosocket, reused_session, server_name, ssl_verify,
251267
send_status_req and 1 or 0,
252268
cosocket[SOCKET_CLIENT_CERT_INDEX],
253269
cosocket[SOCKET_CLIENT_PKEY_INDEX],
270+
alpn_str,
254271
errmsg)
255272

256273
if rc == FFI_NO_REQ_CTX then

0 commit comments

Comments
 (0)