Skip to content

Commit 4e17b37

Browse files
authored
optimization: localize some ngx.* API (#71)
1 parent 01a4bfa commit 4e17b37

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/resty/websocket/server.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local wbproto = require "resty.websocket.protocol"
77
local new_tab = wbproto.new_tab
88
local _recv_frame = wbproto.recv_frame
99
local _send_frame = wbproto.send_frame
10+
local ngx = ngx
1011
local http_ver = ngx.req.http_version
1112
local req_sock = ngx.req.socket
1213
local ngx_header = ngx.header
@@ -16,8 +17,9 @@ local char = string.char
1617
local str_find = string.find
1718
local sha1_bin = ngx.sha1_bin
1819
local base64 = ngx.encode_base64
19-
local ngx = ngx
2020
local read_body = ngx.req.read_body
21+
local ngx_send_headers = ngx.send_headers
22+
local ngx_flush = ngx.flush
2123
local band = bit.band
2224
local rshift = bit.rshift
2325
local type = type
@@ -93,11 +95,11 @@ function _M.new(self, opts)
9395
ngx_header["Content-Type"] = nil
9496

9597
ngx.status = 101
96-
local ok, err = ngx.send_headers()
98+
local ok, err = ngx_send_headers()
9799
if not ok then
98100
return nil, "failed to send response header: " .. (err or "unknown")
99101
end
100-
ok, err = ngx.flush(true)
102+
ok, err = ngx_flush(true)
101103
if not ok then
102104
return nil, "failed to flush response header: " .. (err or "unknown")
103105
end

0 commit comments

Comments
 (0)