Skip to content

fix headers, fix Sec-WebSocket-Protocol , add ORIGIN #5

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
20 changes: 10 additions & 10 deletions lib/resty/websocket/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function _M.new(self, opts)
end


function _M.connect(self, uri, opts)
function _M.connect(self, uri,org, opts)
local sock = self.sock
if not sock then
return nil, "not initialized"
Expand Down Expand Up @@ -90,17 +90,21 @@ function _M.connect(self, uri, opts)
path = "/"
end

local proto_header, sock_opts
local more_header, sock_opts
more_header = ""
if org then
more_header = "\r\nOrigin: ".. org
end

if opts then
local protos = opts.protocols
if protos then
if type(protos) == "table" then
proto_header = "Sec-WebSocket-Protocol: "
.. concat(protos, ",") .. "\r\n"
more_header = more_header.."\r\nSec-WebSocket-Protocol: "
.. concat(protos, ",")

else
proto_header = "Sec-WebSocket-Protocol: " .. protos .. "\r\n"
more_header = more_header.."\r\nSec-WebSocket-Protocol: " .. protos
end
end

Expand All @@ -110,10 +114,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 @@ -137,7 +137,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
.. more_header
.. "\r\nSec-WebSocket-Version: 13"
.. "\r\nConnection: Upgrade\r\n\r\n"

Expand Down