From ea697ccea14105d90cad37ea594a69ce4aa6b059 Mon Sep 17 00:00:00 2001 From: Andreas Garnaes Date: Mon, 5 Nov 2018 14:08:11 +0100 Subject: [PATCH 1/2] Updates for compatibility with async-http --- async-http-faraday.gemspec | 6 ++---- lib/async/http/faraday/adapter.rb | 15 +++----------- spec/async/http/faraday/adapter_spec.rb | 26 ++++++++++++------------- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/async-http-faraday.gemspec b/async-http-faraday.gemspec index a40020f..c451589 100644 --- a/async-http-faraday.gemspec +++ b/async-http-faraday.gemspec @@ -10,13 +10,11 @@ Gem::Specification.new do |spec| spec.summary = "Provides an adaptor between async-http and faraday." spec.homepage = "https://github.com/socketry/async-http" - spec.files = `git ls-files -z`.split("\x0").reject do |f| - f.match(%r{^(test|spec|features)/}) - end + spec.files = [".editorconfig", ".gitignore", ".rspec", ".travis.yml", "Gemfile", "README.md", "Rakefile", "async-http-faraday.gemspec", "lib/async/http/faraday.rb", "lib/async/http/faraday/adapter.rb", "lib/async/http/faraday/version.rb"] spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency("async-http", "~> 0.5") + spec.add_dependency("async-http", "~> 0.37") spec.add_dependency("faraday") spec.add_development_dependency "async-rspec", "~> 1.2" diff --git a/lib/async/http/faraday/adapter.rb b/lib/async/http/faraday/adapter.rb index 393d7b4..c53bb36 100644 --- a/lib/async/http/faraday/adapter.rb +++ b/lib/async/http/faraday/adapter.rb @@ -29,9 +29,9 @@ class Adapter < ::Faraday::Adapter def call(env) super - client = HTTP::Client.new(endpoints_for(env).to_a) + client = HTTP::Client.new(*endpoints_for(env).to_a) - response = client.send_request(env[:method], env[:url].request_uri, env[:request_headers], env[:body] || []) + response = client.send(env[:method], env[:url].request_uri, env[:request_headers], env[:body] || []) save_response(env, response.status, response.body, response.headers, response.reason) @@ -42,16 +42,7 @@ def endpoints_for(env) return to_enum(:endpoints_for, env) unless block_given? if url = env[:url] - port = url.port - port ||= url.scheme == 'https' ? 443 : 80 - - endpoint = Async::IO::Endpoint.tcp(url.hostname, port) - - if url.scheme == 'https' - yield SecureEndpoint.new(endpoint, ssl_context: ssl_context_for(env[:ssl])) - else - yield endpoint - end + yield Async::HTTP::URLEndpoint.new(url) end end diff --git a/spec/async/http/faraday/adapter_spec.rb b/spec/async/http/faraday/adapter_spec.rb index ab6f0e6..71257cc 100644 --- a/spec/async/http/faraday/adapter_spec.rb +++ b/spec/async/http/faraday/adapter_spec.rb @@ -18,37 +18,37 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -require 'async/http/server' require 'async/http/faraday' +require 'async/http/response' +require 'async/http/server' +require 'async/http/url_endpoint' require 'async/reactor' RSpec.describe Async::HTTP::Faraday::Adapter do - let(:server_addresses) {[ - Async::IO::Endpoint.tcp('127.0.0.1', 9294, reuse_port: true) - ]} - + let(:endpoint) { + Async::HTTP::URLEndpoint.parse('http://127.0.0.1:9294') + } + it "client can get resource" do - server = Async::HTTP::Server.new(server_addresses) - - def server.handle_request(request, peer, address) - [200, {}, ["Hello World"]] + app = ->(request) do + Async::HTTP::Response[200, {}, ["Hello World"]] end - - client = Async::HTTP::Client.new(server_addresses) + + server = Async::HTTP::Server.new(app, endpoint) Async::Reactor.run do |task| server_task = task.async do server.run end - conn = Faraday.new(:url => 'http://127.0.0.1:9294') do |faraday| + conn = Faraday.new(:url => endpoint.url) do |faraday| faraday.response :logger faraday.adapter :async_http end response = conn.get("/index") - expect(response.body).to be == "Hello World" + expect(response.body.read).to be == "Hello World" server_task.stop end From 8a43b81f4b6d8e65d9fcbc6eac9b389f31abba4d Mon Sep 17 00:00:00 2001 From: Andreas Garnaes Date: Tue, 6 Nov 2018 12:08:05 +0100 Subject: [PATCH 2/2] Only run Travis with Ruby v2.3 or greater --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0800473..f0b906e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,6 @@ cache: bundler matrix: include: - - rvm: 2.0 - - rvm: 2.1 - - rvm: 2.2 - rvm: 2.3 - rvm: 2.4 - rvm: jruby-head