|
2 | 2 | require "redis/connection/command_helper"
|
3 | 3 | require "redis/errors"
|
4 | 4 | require "socket"
|
5 |
| -require "openssl" |
| 5 | + |
| 6 | +begin |
| 7 | + require "openssl" |
| 8 | +rescue LoadError |
| 9 | + # Not all systems have OpenSSL support |
| 10 | +end |
6 | 11 |
|
7 | 12 | class Redis
|
8 | 13 | module Connection
|
@@ -201,22 +206,24 @@ def self.connect(path, timeout)
|
201 | 206 |
|
202 | 207 | end
|
203 | 208 |
|
204 |
| - class SSLSocket < ::OpenSSL::SSL::SSLSocket |
205 |
| - include SocketMixin |
| 209 | + if defined?(OpenSSL) |
| 210 | + class SSLSocket < ::OpenSSL::SSL::SSLSocket |
| 211 | + include SocketMixin |
206 | 212 |
|
207 |
| - def self.connect(host, port, timeout, ssl_params) |
208 |
| - # Note: this is using Redis::Connection::TCPSocket |
209 |
| - tcp_sock = TCPSocket.connect(host, port, timeout) |
| 213 | + def self.connect(host, port, timeout, ssl_params) |
| 214 | + # Note: this is using Redis::Connection::TCPSocket |
| 215 | + tcp_sock = TCPSocket.connect(host, port, timeout) |
210 | 216 |
|
211 |
| - ctx = OpenSSL::SSL::SSLContext.new |
212 |
| - ctx.set_params(ssl_params) if ssl_params && !ssl_params.empty? |
| 217 | + ctx = OpenSSL::SSL::SSLContext.new |
| 218 | + ctx.set_params(ssl_params) if ssl_params && !ssl_params.empty? |
213 | 219 |
|
214 |
| - ssl_sock = new(tcp_sock, ctx) |
215 |
| - ssl_sock.hostname = host |
216 |
| - ssl_sock.connect |
217 |
| - ssl_sock.post_connection_check(host) |
| 220 | + ssl_sock = new(tcp_sock, ctx) |
| 221 | + ssl_sock.hostname = host |
| 222 | + ssl_sock.connect |
| 223 | + ssl_sock.post_connection_check(host) |
218 | 224 |
|
219 |
| - ssl_sock |
| 225 | + ssl_sock |
| 226 | + end |
220 | 227 | end
|
221 | 228 | end
|
222 | 229 |
|
|
0 commit comments