Skip to content

Commit 12c593a

Browse files
committed
Merge pull request #91 from NovusTheory/master
WSS Support for Sync
2 parents 1ec1ac6 + a7a52b7 commit 12c593a

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ before_install:
1414
fi
1515
- sudo apt-get install $LUA
1616
- sudo apt-get install $LUA_DEV
17+
- sudo apt-get install -y libssl-dev
1718
- lua$LUA_SFX -v
1819
# Install a recent luarocks release
1920
- wget https://github.com/keplerproject/luarocks/archive/v$LUAROCKS_VERSION.tar.gz -O $LUAROCKS_BASE.tar.gz
@@ -32,7 +33,7 @@ install:
3233
- sudo luarocks install luacov-coveralls
3334
- sudo luarocks install lua_cliargs 2.3-3
3435
- sudo luarocks install busted 1.10.0-1
35-
36+
- sudo luarocks install luasec OPENSSL_LIBDIR=/usr/lib/`gcc -print-multiarch`
3637

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

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ The client and server modules depend on:
116116

117117
- luasocket
118118
- luabitop (if not using Lua 5.2 nor luajit)
119+
- luasec
119120
- copas (optionally)
120121
- lua-ev (optionally)
121122

lua-websockets.rockspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ dependencies = {
1717
"lua >= 5.1",
1818
"luasocket",
1919
"luabitop",
20-
"copas"
20+
"copas",
21+
"luasec"
2122
}
2223

2324
build = {

rockspecs/lua-websockets-scm-1.rockspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ dependencies = {
1717
"luasocket",
1818
"luabitop",
1919
"lua-ev",
20-
"copas"
20+
"copas",
21+
"luasec"
2122
}
2223

2324
build = {

src/websocket/client_sync.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ local new = function(ws)
2727
end
2828

2929
self.sock_close = function(self)
30-
self.sock:shutdown()
30+
--self.sock:shutdown() Causes errors?
3131
self.sock:close()
3232
end
3333

src/websocket/sync.lua

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
local frame = require'websocket.frame'
22
local handshake = require'websocket.handshake'
33
local tools = require'websocket.tools'
4+
local ssl = require'ssl'
45
local tinsert = table.insert
56
local tconcat = table.concat
67

7-
88
local receive = function(self)
99
if self.state ~= 'OPEN' and not self.is_closing then
1010
return nil,nil,false,1006,'wrong state'
@@ -117,18 +117,22 @@ local close = function(self,code,reason)
117117
return was_clean,code,reason or ''
118118
end
119119

120-
local connect = function(self,ws_url,ws_protocol)
120+
local connect = function(self,ws_url,ws_protocol,ssl_params)
121121
if self.state ~= 'CLOSED' then
122122
return nil,'wrong state'
123123
end
124124
local protocol,host,port,uri = tools.parse_url(ws_url)
125-
if protocol ~= 'ws' then
126-
return nil,'bad protocol'
127-
end
125+
-- Preconnect (for SSL if needed)
128126
local _,err = self:sock_connect(host,port)
129127
if err then
130128
return nil,err
131129
end
130+
if protocol == 'wss' then
131+
self.sock = ssl.wrap(self.sock, ssl_params)
132+
self.sock:dohandshake()
133+
elseif protocol ~= "ws" then
134+
return nil, 'bad protocol'
135+
end
132136
local ws_protocols_tbl = {''}
133137
if type(ws_protocol) == 'string' then
134138
ws_protocols_tbl = {ws_protocol}

0 commit comments

Comments
 (0)