Skip to content

Commit 2ad2332

Browse files
author
Tom Kemp
committed
Add useTLS/encrypted config options
1 parent e7a06ec commit 2ad2332

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/pusher/client.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def initialize(options = {})
2727
:scheme => 'http',
2828
:port => 80,
2929
}
30+
31+
if options[:useTLS] || options[:encrypted]
32+
default_options[:scheme] = "https"
33+
default_options[:port] = 443
34+
end
35+
3036
merged_options = default_options.merge(options)
3137

3238
if options.has_key?(:host)

spec/client_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,40 @@
100100
end
101101
end
102102

103+
describe 'configuring TLS' do
104+
it 'should set port and scheme if "useTLS" enabled' do
105+
client = Pusher::Client.new({
106+
:useTLS => true,
107+
})
108+
expect(client.scheme).to eq('https')
109+
expect(client.port).to eq(443)
110+
end
111+
112+
it 'should set port and scheme if "encrypted" enabled' do
113+
client = Pusher::Client.new({
114+
:encrypted => true,
115+
})
116+
expect(client.scheme).to eq('https')
117+
expect(client.port).to eq(443)
118+
end
119+
120+
it 'should use non-TLS port and scheme if "encrypted" or "useTLS" are not set' do
121+
client = Pusher::Client.new
122+
expect(client.scheme).to eq('http')
123+
expect(client.port).to eq(80)
124+
end
125+
126+
it 'should override port if "useTLS" option set but a different port is specified' do
127+
client = Pusher::Client.new({
128+
:useTLS => true,
129+
:port => 8443
130+
})
131+
expect(client.scheme).to eq('https')
132+
expect(client.port).to eq(8443)
133+
end
134+
135+
end
136+
103137
describe 'configuring a http proxy' do
104138
it "should be possible to configure everything by setting the http_proxy" do
105139
@client.http_proxy = 'http://someuser:somepassword@proxy.host.com:8080'

0 commit comments

Comments
 (0)