From 23e025cf5799e0afe2e1f503a1310cb4d7e9a2c7 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Thu, 25 Apr 2024 11:30:37 -0300 Subject: [PATCH] Use our fork of em-http-request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’ll use this fork to fix #396. --- Gemfile | 2 ++ ably.gemspec | 2 +- lib/ably/realtime/connection.rb | 2 +- spec/acceptance/realtime/connection_spec.rb | 10 +++++----- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 5d0856f56..814bef0ab 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/ably.gemspec b/ably.gemspec index bbe1dfcb3..1ee9c3d5f 100644 --- a/ably.gemspec +++ b/ably.gemspec @@ -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' diff --git a/lib/ably/realtime/connection.rb b/lib/ably/realtime/connection.rb index 2eeacb12a..3cf106a79 100644 --- a/lib/ably/realtime/connection.rb +++ b/lib/ably/realtime/connection.rb @@ -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) diff --git a/spec/acceptance/realtime/connection_spec.rb b/spec/acceptance/realtime/connection_spec.rb index 4cbc7b405..4d16d79b3 100644 --- a/spec/acceptance/realtime/connection_spec.rb +++ b/spec/acceptance/realtime/connection_spec.rb @@ -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 @@ -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 @@ -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 @@ -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