Skip to content

fix websocket reuse #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/resty/websocket/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ function _M.connect(self, uri, opts)
end
end

if not proto_header then
proto_header = ""
end

local ok, err
if sock_opts then
ok, err = sock:connect(host, port, sock_opts)
Expand All @@ -128,6 +124,16 @@ function _M.connect(self, uri, opts)
if not ok then
return nil, "failed to connect: " .. err
end

-- check if need initialization:
local count,err = sock:getreusedtimes()
if not count then
return nil, "failed to get reuse:" .. err
end
if count > 0 then
return 1
end


-- do the websocket handshake:

Expand All @@ -142,7 +148,7 @@ function _M.connect(self, uri, opts)
local req = "GET " .. path .. " HTTP/1.1\r\nUpgrade: websocket\r\nHost: "
.. host .. ":" .. port
.. "\r\nSec-WebSocket-Key: " .. key
.. proto_header
.. (proto_header or "")
.. "\r\nSec-WebSocket-Version: 13"
.. (origin_header or "")
.. "\r\nConnection: Upgrade\r\n\r\n"
Expand Down