lib/pusher-client/websocket.rb in pusher-client-0.3.1 vs lib/pusher-client/websocket.rb in pusher-client-0.4.0

- old
+ new

@@ -1,27 +1,33 @@ -require 'rubygems' require 'socket' require 'websocket' require 'openssl' module PusherClient class PusherWebSocket WAIT_EXCEPTIONS = [Errno::EAGAIN, Errno::EWOULDBLOCK] WAIT_EXCEPTIONS << IO::WaitReadable if defined?(IO::WaitReadable) - + + CA_FILE = File.expand_path('../../../certs/cacert.pem', __FILE__) + attr_accessor :socket def initialize(url, params = {}) - @hs ||= WebSocket::Handshake::Client.new(:url => url, :version => params[:version]) + @hs ||= WebSocket::Handshake::Client.new(:url => url) @frame ||= WebSocket::Frame::Incoming::Server.new(:version => @hs.version) @socket = TCPSocket.new(@hs.host, @hs.port || 80) + @cert_file = params[:cert_file] if params[:ssl] == true ctx = OpenSSL::SSL::SSLContext.new - ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT - # http://curl.haxx.se/ca/cacert.pem - ctx.ca_file = path_to_cert() + if params[:ssl_verify] + ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT + # http://curl.haxx.se/ca/cacert.pem + ctx.ca_file = @cert_file || CA_FILE + else + ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE + end ssl_sock = OpenSSL::SSL::SSLSocket.new(@socket, ctx) ssl_sock.sync_close = true ssl_sock.connect @@ -41,13 +47,9 @@ raise Exception unless @hs.valid? @handshaked = true break end end - end - - def path_to_cert - File.join(File.dirname(File.expand_path(__FILE__)), '../../certs/cacert.pem') end def send(data, type = :text) raise "no handshake!" unless @handshaked