Skip to content

Commit

Permalink
Allow specifying persistent connection name. (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
cocoahero authored Oct 7, 2024
1 parent 0835c59 commit cda3e8b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/faraday/adapter/net_http_persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def net_http_connection(env)
end

def init_options
options = {name: "Faraday"}
options = {}
options[:name] = @connection_options.fetch(:name, "Faraday")
options[:pool_size] = @connection_options[:pool_size] if @connection_options.key?(:pool_size)
options
end
Expand Down
20 changes: 20 additions & 0 deletions spec/faraday/adapter/net_http_persistent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@
expect(http.pool.size).to eq(5)
end

it "allows to set name on initialize" do
url = URI("https://example.com")

adapter = described_class.new(nil, name: "MyCustomName")

http = adapter.send(:connection, url: url, request: {})

expect(http.name).to eq("MyCustomName")
end

it "defaults name to Faraday on initialize" do
url = URI("https://example.com")

adapter = described_class.new(nil)

http = adapter.send(:connection, url: url, request: {})

expect(http.name).to eq("Faraday")
end

it "allows to set verify_hostname in SSL settings to false" do
url = URI("https://example.com")

Expand Down

0 comments on commit cda3e8b

Please sign in to comment.