Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/lostisland/faraday into 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iMacTia committed Nov 26, 2018
2 parents a37f8c5 + f18a248 commit 5547802
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -288,7 +288,7 @@ end
### NetHttpPersistent
```ruby
conn = Faraday.new(...) do |f|
f.adapter :net_http_persistent do |http| # yields Net::HTTP::Persistent
f.adapter :net_http_persistent, pool_size: 5 do |http| # yields Net::HTTP::Persistent
http.idle_timeout = 100
http.retry_change_requests = true
end
Expand Down
4 changes: 3 additions & 1 deletion lib/faraday/adapter/net_http_persistent.rb
Expand Up @@ -9,7 +9,9 @@ class NetHttpPersistent < NetHttp
def net_http_connection(env)
@cached_connection ||=
if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == [:key, :name]
Net::HTTP::Persistent.new(name: 'Faraday')
options = {name: 'Faraday'}
options[:pool_size] = @connection_options[:pool_size] if @connection_options.key?(:pool_size)
Net::HTTP::Persistent.new(options)
else
Net::HTTP::Persistent.new('Faraday')
end
Expand Down
22 changes: 22 additions & 0 deletions test/adapters/net_http_persistent_test.rb
Expand Up @@ -64,6 +64,28 @@ def test_does_not_reuse_tcp_sockets_when_proxy_changes
end
end

def test_without_custom_connection_config
url = URI('https://example.com:1234')

adapter = Faraday::Adapter::NetHttpPersistent.new

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

# `pool` is only present in net_http_persistent >= 3.0
assert http.pool.size != nil if http.respond_to?(:pool)
end

def test_custom_connection_config
url = URI('https://example.com:1234')

adapter = Faraday::Adapter::NetHttpPersistent.new(nil, {pool_size: 5})

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

# `pool` is only present in net_http_persistent >= 3.0
assert_equal 5, http.pool.size if http.respond_to?(:pool)
end

def test_custom_adapter_config
url = URI('https://example.com:1234')

Expand Down

0 comments on commit 5547802

Please sign in to comment.