Skip to content

Commit ec1fb8b

Browse files
authored
Merge pull request #140 from pusher/add-tls-option
Add use_tls/encrypted config options
2 parents e7a06ec + cdbcb7a commit ec1fb8b

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ channels_client = Pusher::Client.new(
3232
key: 'your-app-key',
3333
secret: 'your-app-secret',
3434
cluster: 'your-app-cluster',
35+
use_tls: true
3536
)
3637
```
3738

38-
The cluster value will set the `host` to `api-<cluster>.pusher.com`.
39+
The `cluster` value will set the `host` to `api-<cluster>.pusher.com`. The `use_tls` value is optional and defaults to `false`. It will set the `scheme` and `port`. Custom `scheme` and `port` values take precendence over `use_tls`.
3940

4041
If you want to set a custom `host` value for your client then you can do so when instantiating a Pusher Channels client like so:
4142

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[:use_tls] || 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 "use_tls" enabled' do
105+
client = Pusher::Client.new({
106+
:use_tls => 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 "use_tls" 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 "use_tls" option set but a different port is specified' do
127+
client = Pusher::Client.new({
128+
:use_tls => 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)