Skip to content

Updates for compatibility with async-http #1

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

Merged
merged 2 commits into from
Nov 6, 2018
Merged
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
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions async-http-faraday.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 3 additions & 12 deletions lib/async/http/faraday/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down
26 changes: 13 additions & 13 deletions spec/async/http/faraday/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down