|
1 | 1 | local frame = require'websocket.frame'
|
2 | 2 | local handshake = require'websocket.handshake'
|
3 | 3 | local tools = require'websocket.tools'
|
| 4 | +local ssl = require'ssl' |
4 | 5 | local tinsert = table.insert
|
5 | 6 | local tconcat = table.concat
|
6 | 7 |
|
7 |
| - |
8 | 8 | local receive = function(self)
|
9 | 9 | if self.state ~= 'OPEN' and not self.is_closing then
|
10 | 10 | return nil,nil,false,1006,'wrong state'
|
@@ -117,18 +117,22 @@ local close = function(self,code,reason)
|
117 | 117 | return was_clean,code,reason or ''
|
118 | 118 | end
|
119 | 119 |
|
120 |
| -local connect = function(self,ws_url,ws_protocol) |
| 120 | +local connect = function(self,ws_url,ws_protocol,ssl_params) |
121 | 121 | if self.state ~= 'CLOSED' then
|
122 | 122 | return nil,'wrong state'
|
123 | 123 | end
|
124 | 124 | 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) |
128 | 126 | local _,err = self:sock_connect(host,port)
|
129 | 127 | if err then
|
130 | 128 | return nil,err
|
131 | 129 | 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 |
132 | 136 | local ws_protocols_tbl = {''}
|
133 | 137 | if type(ws_protocol) == 'string' then
|
134 | 138 | ws_protocols_tbl = {ws_protocol}
|
|
0 commit comments