Skip to content

Commit 4e52a80

Browse files
committed
Allow the config block to return a different wrapper. Fixes #43.
1 parent 2d81bb3 commit 4e52a80

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/async/http/faraday/clients.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def close
3838
# @parameter endpoint [IO::Endpoint::Generic] The endpoint to create the client for.
3939
def make_client(endpoint)
4040
client = Client.new(endpoint, **@options)
41-
@block&.call(client)
42-
return client
41+
42+
return @block&.call(client) || client
4343
end
4444

4545
# Get a client for the given endpoint.

test/async/http/faraday/adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def get_response(url = bound_url, path = '/index', adapter_options: {})
165165

166166
adapter = Faraday.new do |builder|
167167
builder.adapter :async_http do |client|
168-
config_block_invoked = true
168+
config_block_invoked = true; client
169169
end
170170
end
171171

test/async/http/faraday/clients.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@
44
# Copyright, 2024, by Samuel Williams.
55

66
require 'async/http/faraday/clients'
7+
require 'async/http/middleware/location_redirector'
78

89
describe Async::HTTP::Faraday::PersistentClients do
910
let(:clients) {subject.new}
1011

12+
with "a block" do
13+
let(:clients) do
14+
subject.new do |client|
15+
Async::HTTP::Middleware::LocationRedirector.new(client)
16+
end
17+
end
18+
19+
it "can wrap the client with middleware" do
20+
endpoint = Async::HTTP::Endpoint.parse('http://example.com')
21+
client = clients.make_client(endpoint)
22+
23+
expect(client).to be_a(Async::HTTP::Middleware::LocationRedirector)
24+
end
25+
end
26+
1127
with "#make_client" do
1228
it "caches the client" do
1329
endpoint = Async::HTTP::Endpoint.parse('http://example.com')

0 commit comments

Comments
 (0)