mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-21 00:04:04 -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'
|
require 'rack/utils'
|
||||||
|
|
||||||
module Faraday
|
module Faraday
|
||||||
|
class << self
|
||||||
|
attr_accessor :default_adapter
|
||||||
|
end
|
||||||
|
|
||||||
|
self.default_adapter = :net_http
|
||||||
|
|
||||||
module AutoloadHelper
|
module AutoloadHelper
|
||||||
def register_lookup_modules(mods)
|
def register_lookup_modules(mods)
|
||||||
(@lookup_module_index ||= {}).update(mods)
|
(@lookup_module_index ||= {}).update(mods)
|
||||||
|
@ -24,7 +24,10 @@ module Faraday
|
|||||||
build(&block) if block_given?
|
build(&block) if block_given?
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(&block)
|
def build(options = {}, &block)
|
||||||
|
if options[:reset]
|
||||||
|
@handlers.clear
|
||||||
|
end
|
||||||
block.call(self)
|
block.call(self)
|
||||||
run(self.class.inner_app)
|
run(self.class.inner_app)
|
||||||
end
|
end
|
||||||
@ -39,6 +42,10 @@ module Faraday
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_app
|
def to_app
|
||||||
|
if @handlers.empty?
|
||||||
|
build { |b| b.adapter Faraday.default_adapter }
|
||||||
|
end
|
||||||
|
|
||||||
inner_app = @handlers.first
|
inner_app = @handlers.first
|
||||||
@handlers[1..-1].inject(inner_app) { |app, middleware| middleware.call(app) }
|
@handlers[1..-1].inject(inner_app) { |app, middleware| middleware.call(app) }
|
||||||
end
|
end
|
||||||
|
@ -44,8 +44,8 @@ module Faraday
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(&block)
|
def build(options = {}, &block)
|
||||||
@builder.build(&block)
|
@builder.build(options, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(url = nil, headers = nil, &block)
|
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
|
assert_not_equal conn.send(attr).object_id, duped.send(attr).object_id
|
||||||
end
|
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
|
end
|
Loading…
x
Reference in New Issue
Block a user