Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use our fork of em-http-request #399

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in ably.gemspec
gemspec
# TODO remove this line once we’ve published our fork to RubyGems
gem 'ably-em-http-request', git: 'https://github.com/ably-forks/em-http-request', ref: 'ee345b43836422740d729795186dbc7ffec13eda'
2 changes: 1 addition & 1 deletion ably.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_runtime_dependency 'eventmachine', '~> 1.2.6'
spec.add_runtime_dependency 'em-http-request', '~> 1.1'
spec.add_runtime_dependency 'ably-em-http-request', '~> 1.1'
spec.add_runtime_dependency 'statesman', '~> 9.0'
spec.add_runtime_dependency 'faraday', '~> 2.2'
spec.add_runtime_dependency 'faraday-typhoeus', '~> 0.2.0'
Expand Down
2 changes: 1 addition & 1 deletion lib/ably/realtime/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def ping(&block)
def internet_up?
url = "http#{'s' if client.use_tls?}:#{Ably::INTERNET_CHECK.fetch(:url)}"
EventMachine::DefaultDeferrable.new.tap do |deferrable|
EventMachine::HttpRequest.new(url, tls: { verify_peer: true }).get.tap do |http|
EventMachine::AblyHttpRequest::HttpRequest.new(url, tls: { verify_peer: true }).get.tap do |http|
http.errback do
yield false if block_given?
deferrable.fail Ably::Exceptions::ConnectionFailed.new("Unable to connect to #{url}", nil, Ably::Exceptions::Codes::CONNECTION_FAILED)
Expand Down
10 changes: 5 additions & 5 deletions spec/acceptance/realtime/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1702,13 +1702,13 @@ def self.available_states
end

context 'internet up URL protocol' do
let(:http_request) { double('EventMachine::HttpRequest', get: EventMachine::DefaultDeferrable.new) }
let(:http_request) { double('EventMachine::AblyHttpRequest::HttpRequest', get: EventMachine::DefaultDeferrable.new) }

context 'when using TLS for the connection' do
let(:client_options) { default_options.merge(tls: true) }

it 'uses TLS for the Internet check to https://internet-up.ably-realtime.com/is-the-internet-up.txt' do
expect(EventMachine::HttpRequest).to receive(:new).with('https://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request)
expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with('https://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request)
connection.internet_up?
stop_reactor
end
Expand All @@ -1718,7 +1718,7 @@ def self.available_states
let(:client_options) { default_options.merge(tls: false, use_token_auth: true) }

it 'uses TLS for the Internet check to http://internet-up.ably-realtime.com/is-the-internet-up.txt' do
expect(EventMachine::HttpRequest).to receive(:new).with('http://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request)
expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with('http://internet-up.ably-realtime.com/is-the-internet-up.txt', { tls: { verify_peer: true } }).and_return(http_request)
connection.internet_up?
stop_reactor
end
Expand All @@ -1732,7 +1732,7 @@ def self.available_states
let(:client_options) { default_options.merge(tls: true) }

it 'checks the Internet up URL over TLS' do
expect(EventMachine::HttpRequest).to receive(:new).with("https:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new))
expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with("https:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new))
connection.internet_up?
stop_reactor
end
Expand All @@ -1742,7 +1742,7 @@ def self.available_states
let(:client_options) { default_options.merge(tls: false, use_token_auth: true) }

it 'checks the Internet up URL over TLS' do
expect(EventMachine::HttpRequest).to receive(:new).with("http:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new))
expect(EventMachine::AblyHttpRequest::HttpRequest).to receive(:new).with("http:#{Ably::INTERNET_CHECK.fetch(:url)}", { tls: { verify_peer: true } }).and_return(double('request', get: EventMachine::DefaultDeferrable.new))
connection.internet_up?
stop_reactor
end
Expand Down
Loading