mirror of
https://github.com/lostisland/faraday.git
synced 2025-08-30 00:03:09 -04:00
use net/http by default if no middleware is set
This commit is contained in:
parent
a43e0896a6
commit
6220abd088
@ -1,6 +1,12 @@
|
||||
require 'rack/utils'
|
||||
|
||||
module Faraday
|
||||
class << self
|
||||
attr_accessor :default_adapter
|
||||
end
|
||||
|
||||
self.default_adapter = :net_http
|
||||
|
||||
module AutoloadHelper
|
||||
def register_lookup_modules(mods)
|
||||
(@lookup_module_index ||= {}).update(mods)
|
||||
|
@ -24,7 +24,10 @@ module Faraday
|
||||
build(&block) if block_given?
|
||||
end
|
||||
|
||||
def build(&block)
|
||||
def build(options = {}, &block)
|
||||
if options[:reset]
|
||||
@handlers.clear
|
||||
end
|
||||
block.call(self)
|
||||
run(self.class.inner_app)
|
||||
end
|
||||
@ -39,6 +42,10 @@ module Faraday
|
||||
end
|
||||
|
||||
def to_app
|
||||
if @handlers.empty?
|
||||
build { |b| b.adapter Faraday.default_adapter }
|
||||
end
|
||||
|
||||
inner_app = @handlers.first
|
||||
@handlers[1..-1].inject(inner_app) { |app, middleware| middleware.call(app) }
|
||||
end
|
||||
|
@ -44,8 +44,8 @@ module Faraday
|
||||
end
|
||||
end
|
||||
|
||||
def build(&block)
|
||||
@builder.build(&block)
|
||||
def build(options = {}, &block)
|
||||
@builder.build(options, &block)
|
||||
end
|
||||
|
||||
def get(url = nil, headers = nil, &block)
|
||||
|
@ -218,4 +218,13 @@ class TestConnection < Faraday::TestCase
|
||||
assert_not_equal conn.send(attr).object_id, duped.send(attr).object_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_sets_default_adapter_if_none_set
|
||||
conn = Faraday::Connection.new
|
||||
assert_equal 0, conn.builder.handlers.size
|
||||
|
||||
app = conn.to_app
|
||||
mware = conn.builder.handlers[1].call({})
|
||||
assert_kind_of Faraday::Adapter::NetHttp, mware
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user