Skip to content

Commit

Permalink
Use our fork of em-http-request
Browse files Browse the repository at this point in the history
We’ll use this fork to fix #396.
  • Loading branch information
lawrence-forooghian committed Apr 25, 2024
1 parent b89a0e3 commit 23e025c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
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: 'bf2ba35'
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

0 comments on commit 23e025c

Please sign in to comment.