Skip to content
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

WSS Support for Sync & Copas #91

Merged
merged 13 commits into from
Apr 28, 2016
Merged
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ before_install:
fi
- sudo apt-get install $LUA
- sudo apt-get install $LUA_DEV
- sudo apt-get install -y libssl-dev
- lua$LUA_SFX -v
# Install a recent luarocks release
- wget https://github.com/keplerproject/luarocks/archive/v$LUAROCKS_VERSION.tar.gz -O $LUAROCKS_BASE.tar.gz
Expand All @@ -32,7 +33,7 @@ install:
- sudo luarocks install luacov-coveralls
- sudo luarocks install lua_cliargs 2.3-3
- sudo luarocks install busted 1.10.0-1

- sudo luarocks install luasec OPENSSL_LIBDIR=/usr/lib/`gcc -print-multiarch`

script: "sudo luarocks make rockspecs/lua-websockets-scm-1.rockspec && ./test.sh"

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ The client and server modules depend on:

- luasocket
- luabitop (if not using Lua 5.2 nor luajit)
- luasec
- copas (optionally)
- lua-ev (optionally)

Expand Down
3 changes: 2 additions & 1 deletion lua-websockets.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ dependencies = {
"lua >= 5.1",
"luasocket",
"luabitop",
"copas"
"copas",
"luasec"
}

build = {
Expand Down
3 changes: 2 additions & 1 deletion rockspecs/lua-websockets-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ dependencies = {
"luasocket",
"luabitop",
"lua-ev",
"copas"
"copas",
"luasec"
}

build = {
Expand Down
2 changes: 1 addition & 1 deletion src/websocket/client_sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local new = function(ws)
end

self.sock_close = function(self)
self.sock:shutdown()
--self.sock:shutdown() Causes errors?
self.sock:close()
end

Expand Down
14 changes: 9 additions & 5 deletions src/websocket/sync.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
local frame = require'websocket.frame'
local handshake = require'websocket.handshake'
local tools = require'websocket.tools'
local ssl = require'ssl'
local tinsert = table.insert
local tconcat = table.concat


local receive = function(self)
if self.state ~= 'OPEN' and not self.is_closing then
return nil,nil,false,1006,'wrong state'
Expand Down Expand Up @@ -117,18 +117,22 @@ local close = function(self,code,reason)
return was_clean,code,reason or ''
end

local connect = function(self,ws_url,ws_protocol)
local connect = function(self,ws_url,ws_protocol,ssl_params)
if self.state ~= 'CLOSED' then
return nil,'wrong state'
end
local protocol,host,port,uri = tools.parse_url(ws_url)
if protocol ~= 'ws' then
return nil,'bad protocol'
end
-- Preconnect (for SSL if needed)
local _,err = self:sock_connect(host,port)
if err then
return nil,err
end
if protocol == 'wss' then
self.sock = ssl.wrap(self.sock, ssl_params)
self.sock:dohandshake()
elseif protocol ~= "ws" then
return nil, 'bad protocol'
end
local ws_protocols_tbl = {''}
if type(ws_protocol) == 'string' then
ws_protocols_tbl = {ws_protocol}
Expand Down