Skip to content

Commit abdcbd6

Browse files
authored
Merge pull request socketry#1 from andreas/async-http-0.36.2-compat
Updates for compatibility with async-http
2 parents b42359d + 8a43b81 commit abdcbd6

File tree

4 files changed

+18
-32
lines changed

4 files changed

+18
-32
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ cache: bundler
55

66
matrix:
77
include:
8-
- rvm: 2.0
9-
- rvm: 2.1
10-
- rvm: 2.2
118
- rvm: 2.3
129
- rvm: 2.4
1310
- rvm: jruby-head

async-http-faraday.gemspec

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ Gem::Specification.new do |spec|
1010
spec.summary = "Provides an adaptor between async-http and faraday."
1111
spec.homepage = "https://github.com/socketry/async-http"
1212

13-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
14-
f.match(%r{^(test|spec|features)/})
15-
end
13+
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"]
1614
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
1715
spec.require_paths = ["lib"]
1816

19-
spec.add_dependency("async-http", "~> 0.5")
17+
spec.add_dependency("async-http", "~> 0.37")
2018
spec.add_dependency("faraday")
2119

2220
spec.add_development_dependency "async-rspec", "~> 1.2"

lib/async/http/faraday/adapter.rb

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class Adapter < ::Faraday::Adapter
2929
def call(env)
3030
super
3131

32-
client = HTTP::Client.new(endpoints_for(env).to_a)
32+
client = HTTP::Client.new(*endpoints_for(env).to_a)
3333

34-
response = client.send_request(env[:method], env[:url].request_uri, env[:request_headers], env[:body] || [])
34+
response = client.send(env[:method], env[:url].request_uri, env[:request_headers], env[:body] || [])
3535

3636
save_response(env, response.status, response.body, response.headers, response.reason)
3737

@@ -42,16 +42,7 @@ def endpoints_for(env)
4242
return to_enum(:endpoints_for, env) unless block_given?
4343

4444
if url = env[:url]
45-
port = url.port
46-
port ||= url.scheme == 'https' ? 443 : 80
47-
48-
endpoint = Async::IO::Endpoint.tcp(url.hostname, port)
49-
50-
if url.scheme == 'https'
51-
yield SecureEndpoint.new(endpoint, ssl_context: ssl_context_for(env[:ssl]))
52-
else
53-
yield endpoint
54-
end
45+
yield Async::HTTP::URLEndpoint.new(url)
5546
end
5647
end
5748

spec/async/http/faraday/adapter_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,37 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919
# THE SOFTWARE.
2020

21-
require 'async/http/server'
2221
require 'async/http/faraday'
22+
require 'async/http/response'
23+
require 'async/http/server'
24+
require 'async/http/url_endpoint'
2325
require 'async/reactor'
2426

2527
RSpec.describe Async::HTTP::Faraday::Adapter do
26-
let(:server_addresses) {[
27-
Async::IO::Endpoint.tcp('127.0.0.1', 9294, reuse_port: true)
28-
]}
29-
28+
let(:endpoint) {
29+
Async::HTTP::URLEndpoint.parse('http://127.0.0.1:9294')
30+
}
31+
3032
it "client can get resource" do
31-
server = Async::HTTP::Server.new(server_addresses)
32-
33-
def server.handle_request(request, peer, address)
34-
[200, {}, ["Hello World"]]
33+
app = ->(request) do
34+
Async::HTTP::Response[200, {}, ["Hello World"]]
3535
end
36-
37-
client = Async::HTTP::Client.new(server_addresses)
36+
37+
server = Async::HTTP::Server.new(app, endpoint)
3838

3939
Async::Reactor.run do |task|
4040
server_task = task.async do
4141
server.run
4242
end
4343

44-
conn = Faraday.new(:url => 'http://127.0.0.1:9294') do |faraday|
44+
conn = Faraday.new(:url => endpoint.url) do |faraday|
4545
faraday.response :logger
4646
faraday.adapter :async_http
4747
end
4848

4949
response = conn.get("/index")
5050

51-
expect(response.body).to be == "Hello World"
51+
expect(response.body.read).to be == "Hello World"
5252

5353
server_task.stop
5454
end

0 commit comments

Comments
 (0)